diff mbox series

[v3,08/20] coresight: allow etm4x to be built as a module

Message ID 20200717054536.7052-9-tingwei@codeaurora.org (mailing list archive)
State New, archived
Headers show
Series coresight: allow to build coresight as modules | expand

Commit Message

Tingwei Zhang July 17, 2020, 5:45 a.m. UTC
From: Kim Phillips <kim.phillips@arm.com>

Allow to build coresight-etm4x as a module, for ease of development.

- Kconfig becomes a tristate, to allow =m
- append -core to source file name to allow module to
  be called coresight-etm4x by the Makefile
- add an etm4_remove function, for module unload
- add a MODULE_DEVICE_TABLE for autoloading on boot

Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
---
 drivers/hwtracing/coresight/Kconfig           |  5 ++-
 drivers/hwtracing/coresight/Makefile          |  4 +--
 ...resight-etm4x.c => coresight-etm4x-core.c} | 31 ++++++++++++++++++-
 3 files changed, 36 insertions(+), 4 deletions(-)
 rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (98%)

Comments

Mike Leach July 17, 2020, 5:05 p.m. UTC | #1
Hi Tingwei,

Couldn't see 00/20 cover note for this set, so reporting this here as
it relates to etmv4 in part.

The following sequence:-
(There is a load dependency here of course, if I try to load ETMv4
without the coresight core, then I get a lot of missing symbol error
messages - I assume this is expected behaviour?)

root@linaro-developer:/home/linaro/cs-mods# insmod coresight.ko
root@linaro-developer:/home/linaro/cs-mods# insmod coresight-etm4x.ko

correctly loads the coresight core then ETMv4 module.

[ 1208.214674] coresight etm0: CPU0: ETM v4.0 initialized
[ 1208.215534] coresight etm1: CPU1: ETM v4.0 initialized
[ 1208.221020] coresight etm2: CPU2: ETM v4.0 initialized
[ 1208.224757] coresight etm3: CPU3: ETM v4.0 initialized

However, if I then unload the ETMv4 module:-

root@linaro-developer:/home/linaro/cs-mods# rmmod coresight-etm4x.ko

I get a crash:-

[ 1215.963689] ------------[ cut here ]------------
[ 1215.963741] WARNING: CPU: 3 PID: 0 at
drivers/hwtracing/coresight/coresight-etm4x-core.c:1364
etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
[ 1215.967373] Modules linked in: coresight_etm4x(-) coresight [last
unloaded: coresight]
[ 1215.979960] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G        W
  5.8.0-rc5cs-modscs-mods-00020-gc03fe910680d #282
[ 1215.987856] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC (DT)
[ 1215.998531] pstate: 80000085 (Nzcv daIf -PAN -UAO BTYPE=--)
[ 1216.005396] pc : etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
[ 1216.010687] lr : notifier_call_chain+0x5c/0xa0
[ 1216.016926] sp : ffff000009fe7d50
[ 1216.021265] x29: ffff000009fe7d50 x28: 0000000000000000
[ 1216.024653] x27: 0000011b1d1464b5 x26: 0000000000000001
[ 1216.030035] x25: ffff00003c79f888 x24: 0000000000000001
[ 1216.035330] x23: 0000000000000000 x22: 0000000000000000
[ 1216.040626] x21: 0000000000000000 x20: 0000000000000000
[ 1216.045921] x19: ffff000038396480 x18: 0000000000000000
[ 1216.051216] x17: 0000000000000000 x16: 0000000000000000
[ 1216.056510] x15: 0000000000000000 x14: ffffffffffffffff
[ 1216.061806] x13: ffffffffffffffff x12: 0000000000000000
[ 1216.067101] x11: 0000000000000000 x10: 00000000000009b0
[ 1216.072396] x9 : ffff000009fe7e70 x8 : ffff000009fd4010
[ 1216.077690] x7 : 0000000000000000 x6 : 0000000023c2c562
[ 1216.082986] x5 : 00ffffffffffffff x4 : 0000000000000003
[ 1216.088281] x3 : ffff000038396880 x2 : ffff800008d8d280
[ 1216.093576] x1 : ffff80002b1aa000 x0 : 000000005f454c42
[ 1216.098873] Call trace:
[ 1216.104178]  etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
[ 1216.106343]  notifier_call_chain+0x5c/0xa0
[ 1216.112242]  __atomic_notifier_call_chain+0x48/0x60
[ 1216.116236]  cpu_pm_notify+0x44/0x70
[ 1216.121008]  cpu_pm_enter+0x3c/0x80
[ 1216.124829]  psci_enter_domain_idle_state+0x38/0xa8
[ 1216.128040]  cpuidle_enter_state+0x88/0x478
[ 1216.132900]  cpuidle_enter+0x44/0x58
[ 1216.137069]  call_cpuidle+0x40/0x70
[ 1216.140888]  do_idle+0x1e0/0x248
[ 1216.144099]  cpu_startup_entry+0x28/0x98
[ 1216.147574]  secondary_start_kernel+0x1a0/0x1f8
[ 1216.151476] ---[ end trace 97bcd7b8bdd7f9a7 ]---

This happens each time, though the CPU number can change.
Test platform is Dragonboard DB410, linux 5.8-rc5 + this patch set.

Regards

Mike


On Fri, 17 Jul 2020 at 06:48, Tingwei Zhang <tingwei@codeaurora.org> wrote:
>
> From: Kim Phillips <kim.phillips@arm.com>
>
> Allow to build coresight-etm4x as a module, for ease of development.
>
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm4x by the Makefile
> - add an etm4_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
>
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>  drivers/hwtracing/coresight/Makefile          |  4 +--
>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31 ++++++++++++++++++-
>  3 files changed, 36 insertions(+), 4 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm4x.c => coresight-etm4x-core.c} (98%)
>
> diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
> index 8fd9fd139cf3..d6e107bbd30b 100644
> --- a/drivers/hwtracing/coresight/Kconfig
> +++ b/drivers/hwtracing/coresight/Kconfig
> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>           module will be called coresight-etm3x.
>
>  config CORESIGHT_SOURCE_ETM4X
> -       bool "CoreSight Embedded Trace Macrocell 4.x driver"
> +       tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>         depends on ARM64
>         select CORESIGHT_LINKS_AND_SINKS
>         select PID_IN_CONTEXTIDR
> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>           for instruction level tracing. Depending on the implemented version
>           data tracing may also be available.
>
> +         To compile this driver as a module, choose M here: the
> +         module will be called coresight-etm4x.
> +
>  config CORESIGHT_STM
>         tristate "CoreSight System Trace Macrocell driver"
>         depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
> diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
> index d619cfd0abd8..271dc255454f 100644
> --- a/drivers/hwtracing/coresight/Makefile
> +++ b/drivers/hwtracing/coresight/Makefile
> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>                                         coresight-etm3x-sysfs.o
> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> -                                       coresight-etm4x-sysfs.o
> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> similarity index 98%
> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> index 747afc875f91..b5945f62794c 100644
> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> @@ -1536,6 +1536,26 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
>         }
>  };
>
> +static int __exit etm4_remove(struct amba_device *adev)
> +{
> +       struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> +
> +       etm_perf_symlink(drvdata->csdev, false);
> +
> +       if (--etm4_count == 0) {
> +               etm4_cpu_pm_unregister();
> +
> +               cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> +               if (hp_online)
> +                       cpuhp_remove_state_nocalls(hp_online);
> +       }
> +
> +       coresight_unregister(drvdata->csdev);
> +
> +       return 0;
> +}
> +
> +
>  static const struct amba_id etm4_ids[] = {
>         CS_AMBA_ID(0x000bb95d),                 /* Cortex-A53 */
>         CS_AMBA_ID(0x000bb95e),                 /* Cortex-A57 */
> @@ -1553,12 +1573,21 @@ static const struct amba_id etm4_ids[] = {
>         {},
>  };
>
> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> +
>  static struct amba_driver etm4x_driver = {
>         .drv = {
>                 .name   = "coresight-etm4x",
> +               .owner  = THIS_MODULE,
>                 .suppress_bind_attrs = true,
>         },
>         .probe          = etm4_probe,
> +       .remove         = etm4_remove,
>         .id_table       = etm4_ids,
>  };
> -builtin_amba_driver(etm4x_driver);
> +module_amba_driver(etm4x_driver);
> +
> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> +MODULE_LICENSE("GPL v2");
> --
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Tingwei Zhang July 18, 2020, 3:25 a.m. UTC | #2
Hi Mike,

Thanks for reporting this.  This is a good catch.

I was testing on db845c but I didn't encounter this issue with
multiple module load/unload test. I guess it's due to timing difference.
The issue is etm4_cpu_pm_notify() is removed from cpu pm notification
after last etm4 device is removed. There's racing condition when some
etm4 device say etm0 is removed but etm4_cpu_pm_notify() is still
called. I reproduced this issue by manually unbind etm4x device.

The fix is clean etmdrvdata[drvdata->cpu] in etm4_remove() so
etm4_cpu_pm_notify() is gracefully returned. I've verified this on
db845c with manually unbind etm4x device test. Do you mind test
on your db410 as well? I'll put it into v4.

@@ -1542,6 +1543,7 @@ static int __exit etm4_remove(struct amba_device 
*adev)

         etm_perf_symlink(drvdata->csdev, false);

+       etmdrvdata[drvdata->cpu] = NULL;
         if (--etm4_count == 0) {
                 etm4_cpu_pm_unregister();



On 2020-07-18 01:05, Mike Leach wrote:
> Hi Tingwei,
> 
> Couldn't see 00/20 cover note for this set, so reporting this here as
> it relates to etmv4 in part.
> 
> The following sequence:-
> (There is a load dependency here of course, if I try to load ETMv4
> without the coresight core, then I get a lot of missing symbol error
> messages - I assume this is expected behaviour?)

Coresight_etm4x module depends on coresight module, so it's expected
behavior.

> 
> root@linaro-developer:/home/linaro/cs-mods# insmod coresight.ko
> root@linaro-developer:/home/linaro/cs-mods# insmod coresight-etm4x.ko
> 
> correctly loads the coresight core then ETMv4 module.
> 
> [ 1208.214674] coresight etm0: CPU0: ETM v4.0 initialized
> [ 1208.215534] coresight etm1: CPU1: ETM v4.0 initialized
> [ 1208.221020] coresight etm2: CPU2: ETM v4.0 initialized
> [ 1208.224757] coresight etm3: CPU3: ETM v4.0 initialized
> 
> However, if I then unload the ETMv4 module:-
> 
> root@linaro-developer:/home/linaro/cs-mods# rmmod coresight-etm4x.ko
> 
> I get a crash:-
> 
> [ 1215.963689] ------------[ cut here ]------------
> [ 1215.963741] WARNING: CPU: 3 PID: 0 at
> drivers/hwtracing/coresight/coresight-etm4x-core.c:1364
> etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> [ 1215.967373] Modules linked in: coresight_etm4x(-) coresight [last
> unloaded: coresight]
> [ 1215.979960] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G        W
>   5.8.0-rc5cs-modscs-mods-00020-gc03fe910680d #282
> [ 1215.987856] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC
> (DT)
> [ 1215.998531] pstate: 80000085 (Nzcv daIf -PAN -UAO BTYPE=--)
> [ 1216.005396] pc : etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> [ 1216.010687] lr : notifier_call_chain+0x5c/0xa0
> [ 1216.016926] sp : ffff000009fe7d50
> [ 1216.021265] x29: ffff000009fe7d50 x28: 0000000000000000
> [ 1216.024653] x27: 0000011b1d1464b5 x26: 0000000000000001
> [ 1216.030035] x25: ffff00003c79f888 x24: 0000000000000001
> [ 1216.035330] x23: 0000000000000000 x22: 0000000000000000
> [ 1216.040626] x21: 0000000000000000 x20: 0000000000000000
> [ 1216.045921] x19: ffff000038396480 x18: 0000000000000000
> [ 1216.051216] x17: 0000000000000000 x16: 0000000000000000
> [ 1216.056510] x15: 0000000000000000 x14: ffffffffffffffff
> [ 1216.061806] x13: ffffffffffffffff x12: 0000000000000000
> [ 1216.067101] x11: 0000000000000000 x10: 00000000000009b0
> [ 1216.072396] x9 : ffff000009fe7e70 x8 : ffff000009fd4010
> [ 1216.077690] x7 : 0000000000000000 x6 : 0000000023c2c562
> [ 1216.082986] x5 : 00ffffffffffffff x4 : 0000000000000003
> [ 1216.088281] x3 : ffff000038396880 x2 : ffff800008d8d280
> [ 1216.093576] x1 : ffff80002b1aa000 x0 : 000000005f454c42
> [ 1216.098873] Call trace:
> [ 1216.104178]  etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> [ 1216.106343]  notifier_call_chain+0x5c/0xa0
> [ 1216.112242]  __atomic_notifier_call_chain+0x48/0x60
> [ 1216.116236]  cpu_pm_notify+0x44/0x70
> [ 1216.121008]  cpu_pm_enter+0x3c/0x80
> [ 1216.124829]  psci_enter_domain_idle_state+0x38/0xa8
> [ 1216.128040]  cpuidle_enter_state+0x88/0x478
> [ 1216.132900]  cpuidle_enter+0x44/0x58
> [ 1216.137069]  call_cpuidle+0x40/0x70
> [ 1216.140888]  do_idle+0x1e0/0x248
> [ 1216.144099]  cpu_startup_entry+0x28/0x98
> [ 1216.147574]  secondary_start_kernel+0x1a0/0x1f8
> [ 1216.151476] ---[ end trace 97bcd7b8bdd7f9a7 ]---
> 
> This happens each time, though the CPU number can change.
> Test platform is Dragonboard DB410, linux 5.8-rc5 + this patch set.
> 
> Regards
> 
> Mike
> 
> 
> On Fri, 17 Jul 2020 at 06:48, Tingwei Zhang <tingwei@codeaurora.org>
> wrote:
>> 
>> From: Kim Phillips <kim.phillips@arm.com>
>> 
>> Allow to build coresight-etm4x as a module, for ease of development.
>> 
>> - Kconfig becomes a tristate, to allow =m
>> - append -core to source file name to allow module to
>>   be called coresight-etm4x by the Makefile
>> - add an etm4_remove function, for module unload
>> - add a MODULE_DEVICE_TABLE for autoloading on boot
>> 
>> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
>> Cc: Leo Yan <leo.yan@linaro.org>
>> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> Cc: Randy Dunlap <rdunlap@infradead.org>
>> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Russell King <linux@armlinux.org.uk>
>> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
>> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
>> ---
>>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>>  drivers/hwtracing/coresight/Makefile          |  4 +--
>>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31 
>> ++++++++++++++++++-
>>  3 files changed, 36 insertions(+), 4 deletions(-)
>>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> coresight-etm4x-core.c} (98%)
>> 
>> diff --git a/drivers/hwtracing/coresight/Kconfig
> b/drivers/hwtracing/coresight/Kconfig
>> index 8fd9fd139cf3..d6e107bbd30b 100644
>> --- a/drivers/hwtracing/coresight/Kconfig
>> +++ b/drivers/hwtracing/coresight/Kconfig
>> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>>           module will be called coresight-etm3x.
>> 
>>  config CORESIGHT_SOURCE_ETM4X
>> -       bool "CoreSight Embedded Trace Macrocell 4.x driver"
>> +       tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>>         depends on ARM64
>>         select CORESIGHT_LINKS_AND_SINKS
>>         select PID_IN_CONTEXTIDR
>> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>>           for instruction level tracing. Depending on the implemented
> version
>>           data tracing may also be available.
>> 
>> +         To compile this driver as a module, choose M here: the
>> +         module will be called coresight-etm4x.
>> +
>>  config CORESIGHT_STM
>>         tristate "CoreSight System Trace Macrocell driver"
>>         depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) ||
> ARM64
>> diff --git a/drivers/hwtracing/coresight/Makefile
> b/drivers/hwtracing/coresight/Makefile
>> index d619cfd0abd8..271dc255454f 100644
>> --- a/drivers/hwtracing/coresight/Makefile
>> +++ b/drivers/hwtracing/coresight/Makefile
>> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> coresight-funnel.o \
>>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>>                                         coresight-etm3x-sysfs.o
>> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
>> -                                       coresight-etm4x-sysfs.o
>> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
>> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
>>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
>> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> similarity index 98%
>> rename from drivers/hwtracing/coresight/coresight-etm4x.c
>> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
>> index 747afc875f91..b5945f62794c 100644
>> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
>> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> @@ -1536,6 +1536,26 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
>>         }
>>  };
>> 
>> +static int __exit etm4_remove(struct amba_device *adev)
>> +{
>> +       struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
>> +
>> +       etm_perf_symlink(drvdata->csdev, false);
>> +
>> +       if (--etm4_count == 0) {
>> +               etm4_cpu_pm_unregister();
>> +
>> +
> cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
>> +               if (hp_online)
>> +                       cpuhp_remove_state_nocalls(hp_online);
>> +       }
>> +
>> +       coresight_unregister(drvdata->csdev);
>> +
>> +       return 0;
>> +}
>> +
>> +
>>  static const struct amba_id etm4_ids[] = {
>>         CS_AMBA_ID(0x000bb95d),                 /* Cortex-A53 */
>>         CS_AMBA_ID(0x000bb95e),                 /* Cortex-A57 */
>> @@ -1553,12 +1573,21 @@ static const struct amba_id etm4_ids[] = {
>>         {},
>>  };
>> 
>> +MODULE_DEVICE_TABLE(amba, etm4_ids);
>> +
>>  static struct amba_driver etm4x_driver = {
>>         .drv = {
>>                 .name   = "coresight-etm4x",
>> +               .owner  = THIS_MODULE,
>>                 .suppress_bind_attrs = true,
>>         },
>>         .probe          = etm4_probe,
>> +       .remove         = etm4_remove,
>>         .id_table       = etm4_ids,
>>  };
>> -builtin_amba_driver(etm4x_driver);
>> +module_amba_driver(etm4x_driver);
>> +
>> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
>> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
>> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
>> +MODULE_LICENSE("GPL v2");
>> --
>> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> Forum,
>> a Linux Foundation Collaborative Project
>> 
>> 
>> _______________________________________________
>> linux-arm-kernel mailing list
>> linux-arm-kernel@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Mike Leach July 18, 2020, 5:38 p.m. UTC | #3
Hi,

That fix sorts the problem on my board.
However, be aware that the etmv4 PM code changes somewhat due to this
patch [1] that is currently on the linux master branch and will appear
in 5.8-rc6, and there are further new coresight patches in Mathieu's
coresight/next and linux-next.

It may be better to rebase onto coresight/next for the next set.

Regards

Mike

[1] 9b6a3f3633a5 coresight: etmv4: Fix CPU power management setup in
probe() function


On Sat, 18 Jul 2020 at 04:25, <tingwei@codeaurora.org> wrote:
>
> Hi Mike,
>
> Thanks for reporting this.  This is a good catch.
>
> I was testing on db845c but I didn't encounter this issue with
> multiple module load/unload test. I guess it's due to timing difference.
> The issue is etm4_cpu_pm_notify() is removed from cpu pm notification
> after last etm4 device is removed. There's racing condition when some
> etm4 device say etm0 is removed but etm4_cpu_pm_notify() is still
> called. I reproduced this issue by manually unbind etm4x device.
>
> The fix is clean etmdrvdata[drvdata->cpu] in etm4_remove() so
> etm4_cpu_pm_notify() is gracefully returned. I've verified this on
> db845c with manually unbind etm4x device test. Do you mind test
> on your db410 as well? I'll put it into v4.
>
> @@ -1542,6 +1543,7 @@ static int __exit etm4_remove(struct amba_device
> *adev)
>
>          etm_perf_symlink(drvdata->csdev, false);
>
> +       etmdrvdata[drvdata->cpu] = NULL;
>          if (--etm4_count == 0) {
>                  etm4_cpu_pm_unregister();
>
>
>
> On 2020-07-18 01:05, Mike Leach wrote:
> > Hi Tingwei,
> >
> > Couldn't see 00/20 cover note for this set, so reporting this here as
> > it relates to etmv4 in part.
> >
> > The following sequence:-
> > (There is a load dependency here of course, if I try to load ETMv4
> > without the coresight core, then I get a lot of missing symbol error
> > messages - I assume this is expected behaviour?)
>
> Coresight_etm4x module depends on coresight module, so it's expected
> behavior.
>
> >
> > root@linaro-developer:/home/linaro/cs-mods# insmod coresight.ko
> > root@linaro-developer:/home/linaro/cs-mods# insmod coresight-etm4x.ko
> >
> > correctly loads the coresight core then ETMv4 module.
> >
> > [ 1208.214674] coresight etm0: CPU0: ETM v4.0 initialized
> > [ 1208.215534] coresight etm1: CPU1: ETM v4.0 initialized
> > [ 1208.221020] coresight etm2: CPU2: ETM v4.0 initialized
> > [ 1208.224757] coresight etm3: CPU3: ETM v4.0 initialized
> >
> > However, if I then unload the ETMv4 module:-
> >
> > root@linaro-developer:/home/linaro/cs-mods# rmmod coresight-etm4x.ko
> >
> > I get a crash:-
> >
> > [ 1215.963689] ------------[ cut here ]------------
> > [ 1215.963741] WARNING: CPU: 3 PID: 0 at
> > drivers/hwtracing/coresight/coresight-etm4x-core.c:1364
> > etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > [ 1215.967373] Modules linked in: coresight_etm4x(-) coresight [last
> > unloaded: coresight]
> > [ 1215.979960] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G        W
> >   5.8.0-rc5cs-modscs-mods-00020-gc03fe910680d #282
> > [ 1215.987856] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC
> > (DT)
> > [ 1215.998531] pstate: 80000085 (Nzcv daIf -PAN -UAO BTYPE=--)
> > [ 1216.005396] pc : etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > [ 1216.010687] lr : notifier_call_chain+0x5c/0xa0
> > [ 1216.016926] sp : ffff000009fe7d50
> > [ 1216.021265] x29: ffff000009fe7d50 x28: 0000000000000000
> > [ 1216.024653] x27: 0000011b1d1464b5 x26: 0000000000000001
> > [ 1216.030035] x25: ffff00003c79f888 x24: 0000000000000001
> > [ 1216.035330] x23: 0000000000000000 x22: 0000000000000000
> > [ 1216.040626] x21: 0000000000000000 x20: 0000000000000000
> > [ 1216.045921] x19: ffff000038396480 x18: 0000000000000000
> > [ 1216.051216] x17: 0000000000000000 x16: 0000000000000000
> > [ 1216.056510] x15: 0000000000000000 x14: ffffffffffffffff
> > [ 1216.061806] x13: ffffffffffffffff x12: 0000000000000000
> > [ 1216.067101] x11: 0000000000000000 x10: 00000000000009b0
> > [ 1216.072396] x9 : ffff000009fe7e70 x8 : ffff000009fd4010
> > [ 1216.077690] x7 : 0000000000000000 x6 : 0000000023c2c562
> > [ 1216.082986] x5 : 00ffffffffffffff x4 : 0000000000000003
> > [ 1216.088281] x3 : ffff000038396880 x2 : ffff800008d8d280
> > [ 1216.093576] x1 : ffff80002b1aa000 x0 : 000000005f454c42
> > [ 1216.098873] Call trace:
> > [ 1216.104178]  etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > [ 1216.106343]  notifier_call_chain+0x5c/0xa0
> > [ 1216.112242]  __atomic_notifier_call_chain+0x48/0x60
> > [ 1216.116236]  cpu_pm_notify+0x44/0x70
> > [ 1216.121008]  cpu_pm_enter+0x3c/0x80
> > [ 1216.124829]  psci_enter_domain_idle_state+0x38/0xa8
> > [ 1216.128040]  cpuidle_enter_state+0x88/0x478
> > [ 1216.132900]  cpuidle_enter+0x44/0x58
> > [ 1216.137069]  call_cpuidle+0x40/0x70
> > [ 1216.140888]  do_idle+0x1e0/0x248
> > [ 1216.144099]  cpu_startup_entry+0x28/0x98
> > [ 1216.147574]  secondary_start_kernel+0x1a0/0x1f8
> > [ 1216.151476] ---[ end trace 97bcd7b8bdd7f9a7 ]---
> >
> > This happens each time, though the CPU number can change.
> > Test platform is Dragonboard DB410, linux 5.8-rc5 + this patch set.
> >
> > Regards
> >
> > Mike
> >
> >
> > On Fri, 17 Jul 2020 at 06:48, Tingwei Zhang <tingwei@codeaurora.org>
> > wrote:
> >>
> >> From: Kim Phillips <kim.phillips@arm.com>
> >>
> >> Allow to build coresight-etm4x as a module, for ease of development.
> >>
> >> - Kconfig becomes a tristate, to allow =m
> >> - append -core to source file name to allow module to
> >>   be called coresight-etm4x by the Makefile
> >> - add an etm4_remove function, for module unload
> >> - add a MODULE_DEVICE_TABLE for autoloading on boot
> >>
> >> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> >> Cc: Leo Yan <leo.yan@linaro.org>
> >> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> >> Cc: Randy Dunlap <rdunlap@infradead.org>
> >> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: Russell King <linux@armlinux.org.uk>
> >> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> >> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> >> ---
> >>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
> >>  drivers/hwtracing/coresight/Makefile          |  4 +--
> >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31
> >> ++++++++++++++++++-
> >>  3 files changed, 36 insertions(+), 4 deletions(-)
> >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> > coresight-etm4x-core.c} (98%)
> >>
> >> diff --git a/drivers/hwtracing/coresight/Kconfig
> > b/drivers/hwtracing/coresight/Kconfig
> >> index 8fd9fd139cf3..d6e107bbd30b 100644
> >> --- a/drivers/hwtracing/coresight/Kconfig
> >> +++ b/drivers/hwtracing/coresight/Kconfig
> >> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> >>           module will be called coresight-etm3x.
> >>
> >>  config CORESIGHT_SOURCE_ETM4X
> >> -       bool "CoreSight Embedded Trace Macrocell 4.x driver"
> >> +       tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> >>         depends on ARM64
> >>         select CORESIGHT_LINKS_AND_SINKS
> >>         select PID_IN_CONTEXTIDR
> >> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> >>           for instruction level tracing. Depending on the implemented
> > version
> >>           data tracing may also be available.
> >>
> >> +         To compile this driver as a module, choose M here: the
> >> +         module will be called coresight-etm4x.
> >> +
> >>  config CORESIGHT_STM
> >>         tristate "CoreSight System Trace Macrocell driver"
> >>         depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) ||
> > ARM64
> >> diff --git a/drivers/hwtracing/coresight/Makefile
> > b/drivers/hwtracing/coresight/Makefile
> >> index d619cfd0abd8..271dc255454f 100644
> >> --- a/drivers/hwtracing/coresight/Makefile
> >> +++ b/drivers/hwtracing/coresight/Makefile
> >> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> > coresight-funnel.o \
> >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> >>                                         coresight-etm3x-sysfs.o
> >> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> >> -                                       coresight-etm4x-sysfs.o
> >> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> >> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> >> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> > b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >> similarity index 98%
> >> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> >> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> >> index 747afc875f91..b5945f62794c 100644
> >> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> >> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> >> @@ -1536,6 +1536,26 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
> >>         }
> >>  };
> >>
> >> +static int __exit etm4_remove(struct amba_device *adev)
> >> +{
> >> +       struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> >> +
> >> +       etm_perf_symlink(drvdata->csdev, false);
> >> +
> >> +       if (--etm4_count == 0) {
> >> +               etm4_cpu_pm_unregister();
> >> +
> >> +
> > cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> >> +               if (hp_online)
> >> +                       cpuhp_remove_state_nocalls(hp_online);
> >> +       }
> >> +
> >> +       coresight_unregister(drvdata->csdev);
> >> +
> >> +       return 0;
> >> +}
> >> +
> >> +
> >>  static const struct amba_id etm4_ids[] = {
> >>         CS_AMBA_ID(0x000bb95d),                 /* Cortex-A53 */
> >>         CS_AMBA_ID(0x000bb95e),                 /* Cortex-A57 */
> >> @@ -1553,12 +1573,21 @@ static const struct amba_id etm4_ids[] = {
> >>         {},
> >>  };
> >>
> >> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> >> +
> >>  static struct amba_driver etm4x_driver = {
> >>         .drv = {
> >>                 .name   = "coresight-etm4x",
> >> +               .owner  = THIS_MODULE,
> >>                 .suppress_bind_attrs = true,
> >>         },
> >>         .probe          = etm4_probe,
> >> +       .remove         = etm4_remove,
> >>         .id_table       = etm4_ids,
> >>  };
> >> -builtin_amba_driver(etm4x_driver);
> >> +module_amba_driver(etm4x_driver);
> >> +
> >> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> >> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> >> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> >> +MODULE_LICENSE("GPL v2");
> >> --
> >> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> > Forum,
> >> a Linux Foundation Collaborative Project
> >>
> >>
> >> _______________________________________________
> >> linux-arm-kernel mailing list
> >> linux-arm-kernel@lists.infradead.org
> >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel



--
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
Sai Prakash Ranjan July 20, 2020, 6:58 a.m. UTC | #4
Hi Tingwei,

On 2020-07-17 11:15, Tingwei Zhang wrote:
> From: Kim Phillips <kim.phillips@arm.com>
> 
> Allow to build coresight-etm4x as a module, for ease of development.
> 
> - Kconfig becomes a tristate, to allow =m
> - append -core to source file name to allow module to
>   be called coresight-etm4x by the Makefile
> - add an etm4_remove function, for module unload
> - add a MODULE_DEVICE_TABLE for autoloading on boot
> 
> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> Cc: Leo Yan <leo.yan@linaro.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Russell King <linux@armlinux.org.uk>
> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> ---
>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>  drivers/hwtracing/coresight/Makefile          |  4 +--
>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31 ++++++++++++++++++-
>  3 files changed, 36 insertions(+), 4 deletions(-)
>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> coresight-etm4x-core.c} (98%)
> 

<snip>...

Thanks for adding this support. etm4_cpu_pm_unregister() is dropped now 
with change to ETM PM code.
You can base the patches on coresight-next - 
https://git.linaro.org/kernel/coresight.git/log/?h=next

Also I am trying this series on SDM845 MTP (5.8.0-rc5) with Debian 
distribution,
I see below warning when trying to disable ETM, logs below:

root@linaro-developer:~# lsmod
Module                  Size  Used by
cpufreq_powersave      16384  0
cpufreq_conservative    16384  0
msm                   856064  1
coresight_stm          24576  0
crct10dif_ce           20480  1
stm_core               28672  1 coresight_stm
i2c_qcom_geni          24576  0
qcom_rng               16384  0
coresight_tmc          40960  0
coresight_funnel       20480  0
coresight_etm4x        61440  0
coresight_replicator    20480  0
camcc_sdm845           49152  0
ath10k_snoc            53248  0
socinfo                20480  0
ip_tables              32768  0
x_tables               45056  1 ip_tables
ipv6                  458752  26
nf_defrag_ipv6         24576  1 ipv6
root@linaro-developer:~#
root@linaro-developer:~# echo 1 > 
/sys/bus/coresight/devices/tmc_etr0/enable_sink
root@linaro-developer:~# echo 1 > 
/sys/bus/coresight/devices/etm0/enable_source
root@linaro-developer:~# echo 0 > 
/sys/bus/coresight/devices/etm0/enable_source
[  332.855363] ------------[ cut here ]------------
[  332.860175] WARNING: CPU: 0 PID: 0 at 
drivers/hwtracing/coresight/coresight-core.c:227 
coresight_disclaim_device_unlocked+0x28/0x50
[  332.872177] Modules linked in: cpufreq_powersave cpufreq_conservative 
msm(+) coresight_stm crct10dif_ce stm_core i2c_qcom_geni qcom_rng coresi
ght_tmc coresight_funnel coresight_etm4x coresight_replicator 
camcc_sdm845 ath10k_snoc socinfo ip_tables x_tables ipv6 nf_defrag_ipv6
[  332.897043] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G      D W         
5.8.0-rc5-next-20200716-00040-g50ad3222c13f-dirty #80
[  332.908330] Hardware name: Qualcomm Technologies, Inc. SDM845 MTP 
(DT)
[  332.914969] pstate: 80400085 (Nzcv daIf +PAN -UAO BTYPE=--)
[  332.920643] pc : coresight_disclaim_device_unlocked+0x28/0x50
[  332.926543] lr : etm4_disable_hw+0xd8/0x128 [coresight_etm4x]
[  332.932391] sp : ffff800010003ed0
[  332.935775] x29: ffff800010003ed0 x28: ffffb05e1bd13980
[  332.941193] x27: 0000004d7fb06ef3 x26: ffff800010004000
[  332.946606] x25: 0000000000000000 x24: ffffb05e1bd03cc0
[  332.952022] x23: 0000000000000000 x22: 0000000000000000
[  332.957436] x21: ffff800010c73c00 x20: ffff000175547400
[  332.962851] x19: ffff8000103af000 x18: 0000000000000005
[  332.968267] x17: 0000000000000000 x16: ffffb05e1a875f38
[  332.973678] x15: 0000000000000000 x14: ffffb05e1bd13980
[  332.979093] x13: ffff4fa361082000 x12: 000000003474591d
[  332.984507] x11: 0000000000000000 x10: 0000000000001000
[  332.989920] x9 : ffffb05e19a81800 x8 : 000001b2b5503510
[  332.995336] x7 : 000000b2b5503510 x6 : 000000003fd5ea33
[  333.000749] x5 : 00ffffffffffffff x4 : 000000000000b2be
[  333.006162] x3 : ffff0001725c8150 x2 : ffff8000103af168
[  333.011574] x1 : 0000000000000000 x0 : ffff8000103affa4
[  333.016993] Call trace:
[  333.019516]  coresight_disclaim_device_unlocked+0x28/0x50
[  333.025035]  etm4_disable_hw+0xd8/0x128 [coresight_etm4x]
[  333.030552]  flush_smp_call_function_queue+0x154/0x250
[  333.035795]  generic_smp_call_function_single_interrupt+0x18/0x20
[  333.041999]  handle_IPI+0x32c/0x390
[  333.045569]  gic_handle_irq+0x15c/0x160
[  333.049489]  el1_irq+0xb8/0x180
[  333.052709]  cpuidle_enter_state+0xac/0x4e8
[  333.056983]  cpuidle_enter+0x3c/0x50
[  333.060646]  call_cpuidle+0x40/0x70
[  333.064210]  do_idle+0x20c/0x290
[  333.067516]  cpu_startup_entry+0x28/0x70
[  333.071528]  rest_init+0xdc/0xe8
[  333.074847]  arch_call_rest_init+0x14/0x1c
[  333.079027]  start_kernel+0x4e0/0x518
[  333.082764] ---[ end trace 162d5cef8c2b863b ]---
root@linaro-developer:~#

Thanks,
Sai
Sai Prakash Ranjan July 21, 2020, 7:03 a.m. UTC | #5
Hi Tingwei,

On 2020-07-20 12:28, Sai Prakash Ranjan wrote:
> Hi Tingwei,
> 
> On 2020-07-17 11:15, Tingwei Zhang wrote:
>> From: Kim Phillips <kim.phillips@arm.com>
>> 
>> Allow to build coresight-etm4x as a module, for ease of development.
>> 
>> - Kconfig becomes a tristate, to allow =m
>> - append -core to source file name to allow module to
>>   be called coresight-etm4x by the Makefile
>> - add an etm4_remove function, for module unload
>> - add a MODULE_DEVICE_TABLE for autoloading on boot
>> 
>> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
>> Cc: Leo Yan <leo.yan@linaro.org>
>> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> Cc: Randy Dunlap <rdunlap@infradead.org>
>> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: Russell King <linux@armlinux.org.uk>
>> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
>> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
>> ---
>>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>>  drivers/hwtracing/coresight/Makefile          |  4 +--
>>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31 
>> ++++++++++++++++++-
>>  3 files changed, 36 insertions(+), 4 deletions(-)
>>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
>> coresight-etm4x-core.c} (98%)
>> 
> 
> <snip>...
> 
> Thanks for adding this support. etm4_cpu_pm_unregister() is dropped
> now with change to ETM PM code.
> You can base the patches on coresight-next -
> https://git.linaro.org/kernel/coresight.git/log/?h=next
> 
> Also I am trying this series on SDM845 MTP (5.8.0-rc5) with Debian 
> distribution,
> I see below warning when trying to disable ETM, logs below:
> 
> root@linaro-developer:~# lsmod
> Module                  Size  Used by
> cpufreq_powersave      16384  0
> cpufreq_conservative    16384  0
> msm                   856064  1
> coresight_stm          24576  0
> crct10dif_ce           20480  1
> stm_core               28672  1 coresight_stm
> i2c_qcom_geni          24576  0
> qcom_rng               16384  0
> coresight_tmc          40960  0
> coresight_funnel       20480  0
> coresight_etm4x        61440  0
> coresight_replicator    20480  0
> camcc_sdm845           49152  0
> ath10k_snoc            53248  0
> socinfo                20480  0
> ip_tables              32768  0
> x_tables               45056  1 ip_tables
> ipv6                  458752  26
> nf_defrag_ipv6         24576  1 ipv6
> root@linaro-developer:~#
> root@linaro-developer:~# echo 1 >
> /sys/bus/coresight/devices/tmc_etr0/enable_sink
> root@linaro-developer:~# echo 1 > 
> /sys/bus/coresight/devices/etm0/enable_source
> root@linaro-developer:~# echo 0 > 
> /sys/bus/coresight/devices/etm0/enable_source
> [  332.855363] ------------[ cut here ]------------
> [  332.860175] WARNING: CPU: 0 PID: 0 at
> drivers/hwtracing/coresight/coresight-core.c:227
> coresight_disclaim_device_unlocked+0x28/0x50
> [  332.872177] Modules linked in: cpufreq_powersave
> cpufreq_conservative msm(+) coresight_stm crct10dif_ce stm_core
> i2c_qcom_geni qcom_rng coresi
> ght_tmc coresight_funnel coresight_etm4x coresight_replicator
> camcc_sdm845 ath10k_snoc socinfo ip_tables x_tables ipv6
> nf_defrag_ipv6
> [  332.897043] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G      D W
>   5.8.0-rc5-next-20200716-00040-g50ad3222c13f-dirty #80
> [  332.908330] Hardware name: Qualcomm Technologies, Inc. SDM845 MTP 
> (DT)
> [  332.914969] pstate: 80400085 (Nzcv daIf +PAN -UAO BTYPE=--)
> [  332.920643] pc : coresight_disclaim_device_unlocked+0x28/0x50
> [  332.926543] lr : etm4_disable_hw+0xd8/0x128 [coresight_etm4x]
> [  332.932391] sp : ffff800010003ed0
> [  332.935775] x29: ffff800010003ed0 x28: ffffb05e1bd13980
> [  332.941193] x27: 0000004d7fb06ef3 x26: ffff800010004000
> [  332.946606] x25: 0000000000000000 x24: ffffb05e1bd03cc0
> [  332.952022] x23: 0000000000000000 x22: 0000000000000000
> [  332.957436] x21: ffff800010c73c00 x20: ffff000175547400
> [  332.962851] x19: ffff8000103af000 x18: 0000000000000005
> [  332.968267] x17: 0000000000000000 x16: ffffb05e1a875f38
> [  332.973678] x15: 0000000000000000 x14: ffffb05e1bd13980
> [  332.979093] x13: ffff4fa361082000 x12: 000000003474591d
> [  332.984507] x11: 0000000000000000 x10: 0000000000001000
> [  332.989920] x9 : ffffb05e19a81800 x8 : 000001b2b5503510
> [  332.995336] x7 : 000000b2b5503510 x6 : 000000003fd5ea33
> [  333.000749] x5 : 00ffffffffffffff x4 : 000000000000b2be
> [  333.006162] x3 : ffff0001725c8150 x2 : ffff8000103af168
> [  333.011574] x1 : 0000000000000000 x0 : ffff8000103affa4
> [  333.016993] Call trace:
> [  333.019516]  coresight_disclaim_device_unlocked+0x28/0x50
> [  333.025035]  etm4_disable_hw+0xd8/0x128 [coresight_etm4x]
> [  333.030552]  flush_smp_call_function_queue+0x154/0x250
> [  333.035795]  generic_smp_call_function_single_interrupt+0x18/0x20
> [  333.041999]  handle_IPI+0x32c/0x390
> [  333.045569]  gic_handle_irq+0x15c/0x160
> [  333.049489]  el1_irq+0xb8/0x180
> [  333.052709]  cpuidle_enter_state+0xac/0x4e8
> [  333.056983]  cpuidle_enter+0x3c/0x50
> [  333.060646]  call_cpuidle+0x40/0x70
> [  333.064210]  do_idle+0x20c/0x290
> [  333.067516]  cpu_startup_entry+0x28/0x70
> [  333.071528]  rest_init+0xdc/0xe8
> [  333.074847]  arch_call_rest_init+0x14/0x1c
> [  333.079027]  start_kernel+0x4e0/0x518
> [  333.082764] ---[ end trace 162d5cef8c2b863b ]---
> root@linaro-developer:~#
> 

I found that above warning is not due to your changes. If I add
"arm,coresight-loses-context-with-cpu" to SDM845 ETM nodes then
I don't see these warnings, so will add them since idle support
is present on sdm845.

Thanks,
Sai
Mathieu Poirier July 21, 2020, 2:55 p.m. UTC | #6
Hi Tingwei,

On Sat, Jul 18, 2020 at 06:38:08PM +0100, Mike Leach wrote:
> Hi,
> 
> That fix sorts the problem on my board.
> However, be aware that the etmv4 PM code changes somewhat due to this
> patch [1] that is currently on the linux master branch and will appear
> in 5.8-rc6, and there are further new coresight patches in Mathieu's
> coresight/next and linux-next.
> 
> It may be better to rebase onto coresight/next for the next set.
> 

As Mike suggested please rebase on coresight/next and send another revision.

Thanks,
Mathieu

> Regards
> 
> Mike
> 
> [1] 9b6a3f3633a5 coresight: etmv4: Fix CPU power management setup in
> probe() function
> 
> 
> On Sat, 18 Jul 2020 at 04:25, <tingwei@codeaurora.org> wrote:
> >
> > Hi Mike,
> >
> > Thanks for reporting this.  This is a good catch.
> >
> > I was testing on db845c but I didn't encounter this issue with
> > multiple module load/unload test. I guess it's due to timing difference.
> > The issue is etm4_cpu_pm_notify() is removed from cpu pm notification
> > after last etm4 device is removed. There's racing condition when some
> > etm4 device say etm0 is removed but etm4_cpu_pm_notify() is still
> > called. I reproduced this issue by manually unbind etm4x device.
> >
> > The fix is clean etmdrvdata[drvdata->cpu] in etm4_remove() so
> > etm4_cpu_pm_notify() is gracefully returned. I've verified this on
> > db845c with manually unbind etm4x device test. Do you mind test
> > on your db410 as well? I'll put it into v4.
> >
> > @@ -1542,6 +1543,7 @@ static int __exit etm4_remove(struct amba_device
> > *adev)
> >
> >          etm_perf_symlink(drvdata->csdev, false);
> >
> > +       etmdrvdata[drvdata->cpu] = NULL;
> >          if (--etm4_count == 0) {
> >                  etm4_cpu_pm_unregister();
> >
> >
> >
> > On 2020-07-18 01:05, Mike Leach wrote:
> > > Hi Tingwei,
> > >
> > > Couldn't see 00/20 cover note for this set, so reporting this here as
> > > it relates to etmv4 in part.
> > >
> > > The following sequence:-
> > > (There is a load dependency here of course, if I try to load ETMv4
> > > without the coresight core, then I get a lot of missing symbol error
> > > messages - I assume this is expected behaviour?)
> >
> > Coresight_etm4x module depends on coresight module, so it's expected
> > behavior.
> >
> > >
> > > root@linaro-developer:/home/linaro/cs-mods# insmod coresight.ko
> > > root@linaro-developer:/home/linaro/cs-mods# insmod coresight-etm4x.ko
> > >
> > > correctly loads the coresight core then ETMv4 module.
> > >
> > > [ 1208.214674] coresight etm0: CPU0: ETM v4.0 initialized
> > > [ 1208.215534] coresight etm1: CPU1: ETM v4.0 initialized
> > > [ 1208.221020] coresight etm2: CPU2: ETM v4.0 initialized
> > > [ 1208.224757] coresight etm3: CPU3: ETM v4.0 initialized
> > >
> > > However, if I then unload the ETMv4 module:-
> > >
> > > root@linaro-developer:/home/linaro/cs-mods# rmmod coresight-etm4x.ko
> > >
> > > I get a crash:-
> > >
> > > [ 1215.963689] ------------[ cut here ]------------
> > > [ 1215.963741] WARNING: CPU: 3 PID: 0 at
> > > drivers/hwtracing/coresight/coresight-etm4x-core.c:1364
> > > etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > > [ 1215.967373] Modules linked in: coresight_etm4x(-) coresight [last
> > > unloaded: coresight]
> > > [ 1215.979960] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G        W
> > >   5.8.0-rc5cs-modscs-mods-00020-gc03fe910680d #282
> > > [ 1215.987856] Hardware name: Qualcomm Technologies, Inc. APQ 8016 SBC
> > > (DT)
> > > [ 1215.998531] pstate: 80000085 (Nzcv daIf -PAN -UAO BTYPE=--)
> > > [ 1216.005396] pc : etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > > [ 1216.010687] lr : notifier_call_chain+0x5c/0xa0
> > > [ 1216.016926] sp : ffff000009fe7d50
> > > [ 1216.021265] x29: ffff000009fe7d50 x28: 0000000000000000
> > > [ 1216.024653] x27: 0000011b1d1464b5 x26: 0000000000000001
> > > [ 1216.030035] x25: ffff00003c79f888 x24: 0000000000000001
> > > [ 1216.035330] x23: 0000000000000000 x22: 0000000000000000
> > > [ 1216.040626] x21: 0000000000000000 x20: 0000000000000000
> > > [ 1216.045921] x19: ffff000038396480 x18: 0000000000000000
> > > [ 1216.051216] x17: 0000000000000000 x16: 0000000000000000
> > > [ 1216.056510] x15: 0000000000000000 x14: ffffffffffffffff
> > > [ 1216.061806] x13: ffffffffffffffff x12: 0000000000000000
> > > [ 1216.067101] x11: 0000000000000000 x10: 00000000000009b0
> > > [ 1216.072396] x9 : ffff000009fe7e70 x8 : ffff000009fd4010
> > > [ 1216.077690] x7 : 0000000000000000 x6 : 0000000023c2c562
> > > [ 1216.082986] x5 : 00ffffffffffffff x4 : 0000000000000003
> > > [ 1216.088281] x3 : ffff000038396880 x2 : ffff800008d8d280
> > > [ 1216.093576] x1 : ffff80002b1aa000 x0 : 000000005f454c42
> > > [ 1216.098873] Call trace:
> > > [ 1216.104178]  etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
> > > [ 1216.106343]  notifier_call_chain+0x5c/0xa0
> > > [ 1216.112242]  __atomic_notifier_call_chain+0x48/0x60
> > > [ 1216.116236]  cpu_pm_notify+0x44/0x70
> > > [ 1216.121008]  cpu_pm_enter+0x3c/0x80
> > > [ 1216.124829]  psci_enter_domain_idle_state+0x38/0xa8
> > > [ 1216.128040]  cpuidle_enter_state+0x88/0x478
> > > [ 1216.132900]  cpuidle_enter+0x44/0x58
> > > [ 1216.137069]  call_cpuidle+0x40/0x70
> > > [ 1216.140888]  do_idle+0x1e0/0x248
> > > [ 1216.144099]  cpu_startup_entry+0x28/0x98
> > > [ 1216.147574]  secondary_start_kernel+0x1a0/0x1f8
> > > [ 1216.151476] ---[ end trace 97bcd7b8bdd7f9a7 ]---
> > >
> > > This happens each time, though the CPU number can change.
> > > Test platform is Dragonboard DB410, linux 5.8-rc5 + this patch set.
> > >
> > > Regards
> > >
> > > Mike
> > >
> > >
> > > On Fri, 17 Jul 2020 at 06:48, Tingwei Zhang <tingwei@codeaurora.org>
> > > wrote:
> > >>
> > >> From: Kim Phillips <kim.phillips@arm.com>
> > >>
> > >> Allow to build coresight-etm4x as a module, for ease of development.
> > >>
> > >> - Kconfig becomes a tristate, to allow =m
> > >> - append -core to source file name to allow module to
> > >>   be called coresight-etm4x by the Makefile
> > >> - add an etm4_remove function, for module unload
> > >> - add a MODULE_DEVICE_TABLE for autoloading on boot
> > >>
> > >> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
> > >> Cc: Leo Yan <leo.yan@linaro.org>
> > >> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > >> Cc: Randy Dunlap <rdunlap@infradead.org>
> > >> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> > >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > >> Cc: Russell King <linux@armlinux.org.uk>
> > >> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
> > >> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
> > >> ---
> > >>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
> > >>  drivers/hwtracing/coresight/Makefile          |  4 +--
> > >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31
> > >> ++++++++++++++++++-
> > >>  3 files changed, 36 insertions(+), 4 deletions(-)
> > >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
> > > coresight-etm4x-core.c} (98%)
> > >>
> > >> diff --git a/drivers/hwtracing/coresight/Kconfig
> > > b/drivers/hwtracing/coresight/Kconfig
> > >> index 8fd9fd139cf3..d6e107bbd30b 100644
> > >> --- a/drivers/hwtracing/coresight/Kconfig
> > >> +++ b/drivers/hwtracing/coresight/Kconfig
> > >> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
> > >>           module will be called coresight-etm3x.
> > >>
> > >>  config CORESIGHT_SOURCE_ETM4X
> > >> -       bool "CoreSight Embedded Trace Macrocell 4.x driver"
> > >> +       tristate "CoreSight Embedded Trace Macrocell 4.x driver"
> > >>         depends on ARM64
> > >>         select CORESIGHT_LINKS_AND_SINKS
> > >>         select PID_IN_CONTEXTIDR
> > >> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
> > >>           for instruction level tracing. Depending on the implemented
> > > version
> > >>           data tracing may also be available.
> > >>
> > >> +         To compile this driver as a module, choose M here: the
> > >> +         module will be called coresight-etm4x.
> > >> +
> > >>  config CORESIGHT_STM
> > >>         tristate "CoreSight System Trace Macrocell driver"
> > >>         depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) ||
> > > ARM64
> > >> diff --git a/drivers/hwtracing/coresight/Makefile
> > > b/drivers/hwtracing/coresight/Makefile
> > >> index d619cfd0abd8..271dc255454f 100644
> > >> --- a/drivers/hwtracing/coresight/Makefile
> > >> +++ b/drivers/hwtracing/coresight/Makefile
> > >> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
> > > coresight-funnel.o \
> > >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
> > >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
> > >>                                         coresight-etm3x-sysfs.o
> > >> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
> > >> -                                       coresight-etm4x-sysfs.o
> > >> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
> > >> +coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
> > >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
> > >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
> > >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
> > >> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
> > > b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >> similarity index 98%
> > >> rename from drivers/hwtracing/coresight/coresight-etm4x.c
> > >> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >> index 747afc875f91..b5945f62794c 100644
> > >> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
> > >> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
> > >> @@ -1536,6 +1536,26 @@ static struct amba_cs_uci_id uci_id_etm4[] = {
> > >>         }
> > >>  };
> > >>
> > >> +static int __exit etm4_remove(struct amba_device *adev)
> > >> +{
> > >> +       struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
> > >> +
> > >> +       etm_perf_symlink(drvdata->csdev, false);
> > >> +
> > >> +       if (--etm4_count == 0) {
> > >> +               etm4_cpu_pm_unregister();
> > >> +
> > >> +
> > > cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
> > >> +               if (hp_online)
> > >> +                       cpuhp_remove_state_nocalls(hp_online);
> > >> +       }
> > >> +
> > >> +       coresight_unregister(drvdata->csdev);
> > >> +
> > >> +       return 0;
> > >> +}
> > >> +
> > >> +
> > >>  static const struct amba_id etm4_ids[] = {
> > >>         CS_AMBA_ID(0x000bb95d),                 /* Cortex-A53 */
> > >>         CS_AMBA_ID(0x000bb95e),                 /* Cortex-A57 */
> > >> @@ -1553,12 +1573,21 @@ static const struct amba_id etm4_ids[] = {
> > >>         {},
> > >>  };
> > >>
> > >> +MODULE_DEVICE_TABLE(amba, etm4_ids);
> > >> +
> > >>  static struct amba_driver etm4x_driver = {
> > >>         .drv = {
> > >>                 .name   = "coresight-etm4x",
> > >> +               .owner  = THIS_MODULE,
> > >>                 .suppress_bind_attrs = true,
> > >>         },
> > >>         .probe          = etm4_probe,
> > >> +       .remove         = etm4_remove,
> > >>         .id_table       = etm4_ids,
> > >>  };
> > >> -builtin_amba_driver(etm4x_driver);
> > >> +module_amba_driver(etm4x_driver);
> > >> +
> > >> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
> > >> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
> > >> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
> > >> +MODULE_LICENSE("GPL v2");
> > >> --
> > >> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
> > > Forum,
> > >> a Linux Foundation Collaborative Project
> > >>
> > >>
> > >> _______________________________________________
> > >> linux-arm-kernel mailing list
> > >> linux-arm-kernel@lists.infradead.org
> > >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> 
> 
> 
> --
> Mike Leach
> Principal Engineer, ARM Ltd.
> Manchester Design Centre. UK
Tingwei Zhang July 21, 2020, 11:22 p.m. UTC | #7
On 2020-07-21 22:55, Mathieu Poirier wrote:
> Hi Tingwei,
> 
> On Sat, Jul 18, 2020 at 06:38:08PM +0100, Mike Leach wrote:
>> Hi,
>> 
>> That fix sorts the problem on my board.
>> However, be aware that the etmv4 PM code changes somewhat due to this
>> patch [1] that is currently on the linux master branch and will appear
>> in 5.8-rc6, and there are further new coresight patches in Mathieu's
>> coresight/next and linux-next.
>> 
>> It may be better to rebase onto coresight/next for the next set.
>> 
> 
> As Mike suggested please rebase on coresight/next and send another
> revision.
> 
> Thanks,
> Mathieu
> 

Sure.  I'll rebase to coresight/next and send another revision.

>> Regards
>> 
>> Mike
>> 
>> [1] 9b6a3f3633a5 coresight: etmv4: Fix CPU power management setup in
>> probe() function
>> 
>> 
>> On Sat, 18 Jul 2020 at 04:25, <tingwei@codeaurora.org> wrote:
>> >
>> > Hi Mike,
>> >
>> > Thanks for reporting this.  This is a good catch.
>> >
>> > I was testing on db845c but I didn't encounter this issue with
>> > multiple module load/unload test. I guess it's due to timing
> difference.
>> > The issue is etm4_cpu_pm_notify() is removed from cpu pm notification
>> > after last etm4 device is removed. There's racing condition when some
>> > etm4 device say etm0 is removed but etm4_cpu_pm_notify() is still
>> > called. I reproduced this issue by manually unbind etm4x device.
>> >
>> > The fix is clean etmdrvdata[drvdata->cpu] in etm4_remove() so
>> > etm4_cpu_pm_notify() is gracefully returned. I've verified this on
>> > db845c with manually unbind etm4x device test. Do you mind test
>> > on your db410 as well? I'll put it into v4.
>> >
>> > @@ -1542,6 +1543,7 @@ static int __exit etm4_remove(struct amba_device
>> > *adev)
>> >
>> >          etm_perf_symlink(drvdata->csdev, false);
>> >
>> > +       etmdrvdata[drvdata->cpu] = NULL;
>> >          if (--etm4_count == 0) {
>> >                  etm4_cpu_pm_unregister();
>> >
>> >
>> >
>> > On 2020-07-18 01:05, Mike Leach wrote:
>> > > Hi Tingwei,
>> > >
>> > > Couldn't see 00/20 cover note for this set, so reporting this here
> as
>> > > it relates to etmv4 in part.
>> > >
>> > > The following sequence:-
>> > > (There is a load dependency here of course, if I try to load ETMv4
>> > > without the coresight core, then I get a lot of missing symbol error
>> > > messages - I assume this is expected behaviour?)
>> >
>> > Coresight_etm4x module depends on coresight module, so it's expected
>> > behavior.
>> >
>> > >
>> > > root@linaro-developer:/home/linaro/cs-mods# insmod coresight.ko
>> > > root@linaro-developer:/home/linaro/cs-mods# insmod
> coresight-etm4x.ko
>> > >
>> > > correctly loads the coresight core then ETMv4 module.
>> > >
>> > > [ 1208.214674] coresight etm0: CPU0: ETM v4.0 initialized
>> > > [ 1208.215534] coresight etm1: CPU1: ETM v4.0 initialized
>> > > [ 1208.221020] coresight etm2: CPU2: ETM v4.0 initialized
>> > > [ 1208.224757] coresight etm3: CPU3: ETM v4.0 initialized
>> > >
>> > > However, if I then unload the ETMv4 module:-
>> > >
>> > > root@linaro-developer:/home/linaro/cs-mods# rmmod coresight-etm4x.ko
>> > >
>> > > I get a crash:-
>> > >
>> > > [ 1215.963689] ------------[ cut here ]------------
>> > > [ 1215.963741] WARNING: CPU: 3 PID: 0 at
>> > > drivers/hwtracing/coresight/coresight-etm4x-core.c:1364
>> > > etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
>> > > [ 1215.967373] Modules linked in: coresight_etm4x(-) coresight [last
>> > > unloaded: coresight]
>> > > [ 1215.979960] CPU: 3 PID: 0 Comm: swapper/3 Tainted: G        W
>> > >   5.8.0-rc5cs-modscs-mods-00020-gc03fe910680d #282
>> > > [ 1215.987856] Hardware name: Qualcomm Technologies, Inc. APQ 8016
> SBC
>> > > (DT)
>> > > [ 1215.998531] pstate: 80000085 (Nzcv daIf -PAN -UAO BTYPE=--)
>> > > [ 1216.005396] pc : etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
>> > > [ 1216.010687] lr : notifier_call_chain+0x5c/0xa0
>> > > [ 1216.016926] sp : ffff000009fe7d50
>> > > [ 1216.021265] x29: ffff000009fe7d50 x28: 0000000000000000
>> > > [ 1216.024653] x27: 0000011b1d1464b5 x26: 0000000000000001
>> > > [ 1216.030035] x25: ffff00003c79f888 x24: 0000000000000001
>> > > [ 1216.035330] x23: 0000000000000000 x22: 0000000000000000
>> > > [ 1216.040626] x21: 0000000000000000 x20: 0000000000000000
>> > > [ 1216.045921] x19: ffff000038396480 x18: 0000000000000000
>> > > [ 1216.051216] x17: 0000000000000000 x16: 0000000000000000
>> > > [ 1216.056510] x15: 0000000000000000 x14: ffffffffffffffff
>> > > [ 1216.061806] x13: ffffffffffffffff x12: 0000000000000000
>> > > [ 1216.067101] x11: 0000000000000000 x10: 00000000000009b0
>> > > [ 1216.072396] x9 : ffff000009fe7e70 x8 : ffff000009fd4010
>> > > [ 1216.077690] x7 : 0000000000000000 x6 : 0000000023c2c562
>> > > [ 1216.082986] x5 : 00ffffffffffffff x4 : 0000000000000003
>> > > [ 1216.088281] x3 : ffff000038396880 x2 : ffff800008d8d280
>> > > [ 1216.093576] x1 : ffff80002b1aa000 x0 : 000000005f454c42
>> > > [ 1216.098873] Call trace:
>> > > [ 1216.104178]  etm4_cpu_pm_notify+0xad8/0xb48 [coresight_etm4x]
>> > > [ 1216.106343]  notifier_call_chain+0x5c/0xa0
>> > > [ 1216.112242]  __atomic_notifier_call_chain+0x48/0x60
>> > > [ 1216.116236]  cpu_pm_notify+0x44/0x70
>> > > [ 1216.121008]  cpu_pm_enter+0x3c/0x80
>> > > [ 1216.124829]  psci_enter_domain_idle_state+0x38/0xa8
>> > > [ 1216.128040]  cpuidle_enter_state+0x88/0x478
>> > > [ 1216.132900]  cpuidle_enter+0x44/0x58
>> > > [ 1216.137069]  call_cpuidle+0x40/0x70
>> > > [ 1216.140888]  do_idle+0x1e0/0x248
>> > > [ 1216.144099]  cpu_startup_entry+0x28/0x98
>> > > [ 1216.147574]  secondary_start_kernel+0x1a0/0x1f8
>> > > [ 1216.151476] ---[ end trace 97bcd7b8bdd7f9a7 ]---
>> > >
>> > > This happens each time, though the CPU number can change.
>> > > Test platform is Dragonboard DB410, linux 5.8-rc5 + this patch set.
>> > >
>> > > Regards
>> > >
>> > > Mike
>> > >
>> > >
>> > > On Fri, 17 Jul 2020 at 06:48, Tingwei Zhang <tingwei@codeaurora.org>
>> > > wrote:
>> > >>
>> > >> From: Kim Phillips <kim.phillips@arm.com>
>> > >>
>> > >> Allow to build coresight-etm4x as a module, for ease of
> development.
>> > >>
>> > >> - Kconfig becomes a tristate, to allow =m
>> > >> - append -core to source file name to allow module to
>> > >>   be called coresight-etm4x by the Makefile
>> > >> - add an etm4_remove function, for module unload
>> > >> - add a MODULE_DEVICE_TABLE for autoloading on boot
>> > >>
>> > >> Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
>> > >> Cc: Leo Yan <leo.yan@linaro.org>
>> > >> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>> > >> Cc: Randy Dunlap <rdunlap@infradead.org>
>> > >> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
>> > >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> > >> Cc: Russell King <linux@armlinux.org.uk>
>> > >> Signed-off-by: Kim Phillips <kim.phillips@arm.com>
>> > >> Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org>
>> > >> ---
>> > >>  drivers/hwtracing/coresight/Kconfig           |  5 ++-
>> > >>  drivers/hwtracing/coresight/Makefile          |  4 +--
>> > >>  ...resight-etm4x.c => coresight-etm4x-core.c} | 31
>> > >> ++++++++++++++++++-
>> > >>  3 files changed, 36 insertions(+), 4 deletions(-)
>> > >>  rename drivers/hwtracing/coresight/{coresight-etm4x.c =>
>> > > coresight-etm4x-core.c} (98%)
>> > >>
>> > >> diff --git a/drivers/hwtracing/coresight/Kconfig
>> > > b/drivers/hwtracing/coresight/Kconfig
>> > >> index 8fd9fd139cf3..d6e107bbd30b 100644
>> > >> --- a/drivers/hwtracing/coresight/Kconfig
>> > >> +++ b/drivers/hwtracing/coresight/Kconfig
>> > >> @@ -78,7 +78,7 @@ config CORESIGHT_SOURCE_ETM3X
>> > >>           module will be called coresight-etm3x.
>> > >>
>> > >>  config CORESIGHT_SOURCE_ETM4X
>> > >> -       bool "CoreSight Embedded Trace Macrocell 4.x driver"
>> > >> +       tristate "CoreSight Embedded Trace Macrocell 4.x driver"
>> > >>         depends on ARM64
>> > >>         select CORESIGHT_LINKS_AND_SINKS
>> > >>         select PID_IN_CONTEXTIDR
>> > >> @@ -88,6 +88,9 @@ config CORESIGHT_SOURCE_ETM4X
>> > >>           for instruction level tracing. Depending on the
> implemented
>> > > version
>> > >>           data tracing may also be available.
>> > >>
>> > >> +         To compile this driver as a module, choose M here: the
>> > >> +         module will be called coresight-etm4x.
>> > >> +
>> > >>  config CORESIGHT_STM
>> > >>         tristate "CoreSight System Trace Macrocell driver"
>> > >>         depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) ||
>> > > ARM64
>> > >> diff --git a/drivers/hwtracing/coresight/Makefile
>> > > b/drivers/hwtracing/coresight/Makefile
>> > >> index d619cfd0abd8..271dc255454f 100644
>> > >> --- a/drivers/hwtracing/coresight/Makefile
>> > >> +++ b/drivers/hwtracing/coresight/Makefile
>> > >> @@ -14,8 +14,8 @@ obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) +=
>> > > coresight-funnel.o \
>> > >>  obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
>> > >>  coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
>> > >>                                         coresight-etm3x-sysfs.o
>> > >> -obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
>> > >> -                                       coresight-etm4x-sysfs.o
>> > >> +obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
>> > >> +coresight-etm4x-y := coresight-etm4x-core.o
> coresight-etm4x-sysfs.o
>> > >>  obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
>> > >>  obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
>> > >>  obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
>> > >> diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c
>> > > b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> > >> similarity index 98%
>> > >> rename from drivers/hwtracing/coresight/coresight-etm4x.c
>> > >> rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
>> > >> index 747afc875f91..b5945f62794c 100644
>> > >> --- a/drivers/hwtracing/coresight/coresight-etm4x.c
>> > >> +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
>> > >> @@ -1536,6 +1536,26 @@ static struct amba_cs_uci_id uci_id_etm4[] =
> {
>> > >>         }
>> > >>  };
>> > >>
>> > >> +static int __exit etm4_remove(struct amba_device *adev)
>> > >> +{
>> > >> +       struct etmv4_drvdata *drvdata =
> dev_get_drvdata(&adev->dev);
>> > >> +
>> > >> +       etm_perf_symlink(drvdata->csdev, false);
>> > >> +
>> > >> +       if (--etm4_count == 0) {
>> > >> +               etm4_cpu_pm_unregister();
>> > >> +
>> > >> +
>> > > cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
>> > >> +               if (hp_online)
>> > >> +                       cpuhp_remove_state_nocalls(hp_online);
>> > >> +       }
>> > >> +
>> > >> +       coresight_unregister(drvdata->csdev);
>> > >> +
>> > >> +       return 0;
>> > >> +}
>> > >> +
>> > >> +
>> > >>  static const struct amba_id etm4_ids[] = {
>> > >>         CS_AMBA_ID(0x000bb95d),                 /* Cortex-A53 */
>> > >>         CS_AMBA_ID(0x000bb95e),                 /* Cortex-A57 */
>> > >> @@ -1553,12 +1573,21 @@ static const struct amba_id etm4_ids[] = {
>> > >>         {},
>> > >>  };
>> > >>
>> > >> +MODULE_DEVICE_TABLE(amba, etm4_ids);
>> > >> +
>> > >>  static struct amba_driver etm4x_driver = {
>> > >>         .drv = {
>> > >>                 .name   = "coresight-etm4x",
>> > >> +               .owner  = THIS_MODULE,
>> > >>                 .suppress_bind_attrs = true,
>> > >>         },
>> > >>         .probe          = etm4_probe,
>> > >> +       .remove         = etm4_remove,
>> > >>         .id_table       = etm4_ids,
>> > >>  };
>> > >> -builtin_amba_driver(etm4x_driver);
>> > >> +module_amba_driver(etm4x_driver);
>> > >> +
>> > >> +MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
>> > >> +MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
>> > >> +MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
>> > >> +MODULE_LICENSE("GPL v2");
>> > >> --
>> > >> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora
>> > > Forum,
>> > >> a Linux Foundation Collaborative Project
>> > >>
>> > >>
>> > >> _______________________________________________
>> > >> linux-arm-kernel mailing list
>> > >> linux-arm-kernel@lists.infradead.org
>> > >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>> 
>> 
>> 
>> --
>> Mike Leach
>> Principal Engineer, ARM Ltd.
>> Manchester Design Centre. UK
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
diff mbox series

Patch

diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig
index 8fd9fd139cf3..d6e107bbd30b 100644
--- a/drivers/hwtracing/coresight/Kconfig
+++ b/drivers/hwtracing/coresight/Kconfig
@@ -78,7 +78,7 @@  config CORESIGHT_SOURCE_ETM3X
 	  module will be called coresight-etm3x.
 
 config CORESIGHT_SOURCE_ETM4X
-	bool "CoreSight Embedded Trace Macrocell 4.x driver"
+	tristate "CoreSight Embedded Trace Macrocell 4.x driver"
 	depends on ARM64
 	select CORESIGHT_LINKS_AND_SINKS
 	select PID_IN_CONTEXTIDR
@@ -88,6 +88,9 @@  config CORESIGHT_SOURCE_ETM4X
 	  for instruction level tracing. Depending on the implemented version
 	  data tracing may also be available.
 
+	  To compile this driver as a module, choose M here: the
+	  module will be called coresight-etm4x.
+
 config CORESIGHT_STM
 	tristate "CoreSight System Trace Macrocell driver"
 	depends on (ARM && !(CPU_32v3 || CPU_32v4 || CPU_32v4T)) || ARM64
diff --git a/drivers/hwtracing/coresight/Makefile b/drivers/hwtracing/coresight/Makefile
index d619cfd0abd8..271dc255454f 100644
--- a/drivers/hwtracing/coresight/Makefile
+++ b/drivers/hwtracing/coresight/Makefile
@@ -14,8 +14,8 @@  obj-$(CONFIG_CORESIGHT_LINKS_AND_SINKS) += coresight-funnel.o \
 obj-$(CONFIG_CORESIGHT_SOURCE_ETM3X) += coresight-etm3x.o
 coresight-etm3x-y := coresight-etm3x-core.o coresight-etm-cp14.o \
 					coresight-etm3x-sysfs.o
-obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o \
-					coresight-etm4x-sysfs.o
+obj-$(CONFIG_CORESIGHT_SOURCE_ETM4X) += coresight-etm4x.o
+coresight-etm4x-y := coresight-etm4x-core.o coresight-etm4x-sysfs.o
 obj-$(CONFIG_CORESIGHT_STM) += coresight-stm.o
 obj-$(CONFIG_CORESIGHT_CPU_DEBUG) += coresight-cpu-debug.o
 obj-$(CONFIG_CORESIGHT_CATU) += coresight-catu.o
diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c
similarity index 98%
rename from drivers/hwtracing/coresight/coresight-etm4x.c
rename to drivers/hwtracing/coresight/coresight-etm4x-core.c
index 747afc875f91..b5945f62794c 100644
--- a/drivers/hwtracing/coresight/coresight-etm4x.c
+++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c
@@ -1536,6 +1536,26 @@  static struct amba_cs_uci_id uci_id_etm4[] = {
 	}
 };
 
+static int __exit etm4_remove(struct amba_device *adev)
+{
+	struct etmv4_drvdata *drvdata = dev_get_drvdata(&adev->dev);
+
+	etm_perf_symlink(drvdata->csdev, false);
+
+	if (--etm4_count == 0) {
+		etm4_cpu_pm_unregister();
+
+		cpuhp_remove_state_nocalls(CPUHP_AP_ARM_CORESIGHT_STARTING);
+		if (hp_online)
+			cpuhp_remove_state_nocalls(hp_online);
+	}
+
+	coresight_unregister(drvdata->csdev);
+
+	return 0;
+}
+
+
 static const struct amba_id etm4_ids[] = {
 	CS_AMBA_ID(0x000bb95d),			/* Cortex-A53 */
 	CS_AMBA_ID(0x000bb95e),			/* Cortex-A57 */
@@ -1553,12 +1573,21 @@  static const struct amba_id etm4_ids[] = {
 	{},
 };
 
+MODULE_DEVICE_TABLE(amba, etm4_ids);
+
 static struct amba_driver etm4x_driver = {
 	.drv = {
 		.name   = "coresight-etm4x",
+		.owner  = THIS_MODULE,
 		.suppress_bind_attrs = true,
 	},
 	.probe		= etm4_probe,
+	.remove         = etm4_remove,
 	.id_table	= etm4_ids,
 };
-builtin_amba_driver(etm4x_driver);
+module_amba_driver(etm4x_driver);
+
+MODULE_AUTHOR("Pratik Patel <pratikp@codeaurora.org>");
+MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
+MODULE_DESCRIPTION("Arm CoreSight Program Flow Trace v4 driver");
+MODULE_LICENSE("GPL v2");