coresight: cti: Add PM runtime call in enable_store
v3 cover coresight: cti: Add PM runtime call in enable_store
Changes since v2:
* Reword first commit message and add fixes tag
* Pickup Jinlong's tested-by tags
----
This should be a slight improvement on Jinlong's previous version. Now it's not possible to trigger the error message from pm_runtime_put() by calling disable twice.
It's also similar to the original pre-breaking change version where pm_runtime_put() was only called if the device was actually disabled, but with one difference: Previously pm_runtime_put() was only called once for the last disable call, but because of the reference counting in pm_runtime, it should have been called once for each enable call. This meant that the clock would have never been disabled if there were ever multiple enable calls. This is now fixed.
The third commit is a refactor and doesn't need to be backported. I removed one of the atomic types because it didn't appear to be required. Maybe it was added for a reason which I'm not aware of, if so it should be pretty easy to drop that change.
James Clark (2):
coresight: cti: Prevent negative values of enable count
coresight: cti: Remove atomic type from enable_req_count
Mao Jinlong (1):
coresight: cti: Add PM runtime call in enable_store
.../hwtracing/coresight/coresight-cti-core.c | 23 ++++++++++++------- .../hwtracing/coresight/coresight-cti-sysfs.c | 15 +++++++++--- drivers/hwtracing/coresight/coresight-cti.h | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-)
base-commit: 88603b6dc419445847923fcb7fe5080067a30f98
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 1/3 coresight: cti: Prevent negative values of enable count
Writing 0 to the enable control repeatedly results in a negative value for enable_req_count. After this, writing 1 to the enable control appears to not work until the count returns to positive.
Change it so that it's impossible for enable_req_count to be < 0. Return an error to indicate that the disable request was invalid.
--- drivers/hwtracing/coresight/coresight-cti-core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-cti-core.c +9 -2
@@ -151,9 +151,16 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) {struct cti_config *config = &drvdata->config;struct coresight_device *csdev = drvdata->csdev; +int ret =0 ;spin_lock (&drvdata->spinlock); +/* don't allow negative refcounts, return an error */ +if (!atomic_read (&drvdata->config.enable_req_count)) { + ret = -EINVAL ; + goto cti_not_disabled; + } +/* check refcount - disable on 0 */ if (atomic_dec_return (&drvdata->config.enable_req_count) >0 ) goto cti_not_disabled;
@@ -171,12 +178,12 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)coresight_disclaim_device_unlocked (csdev);CS_LOCK (drvdata->base);spin_unlock (&drvdata->spinlock); -return 0 ; +return ret;/* not disabled this call */ cti_not_disabled:spin_unlock (&drvdata->spinlock); -return 0 ; +return ret; }void cti_write_single_reg (struct cti_drvdata *drvdata,int offset,u32 value)
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v3 1/3] coresight: cti: Prevent negative values of enable count
Quoted 52 lines · James Clark
Writing 0 to the enable control repeatedly results in a negative value for
enable_req_count. After this, writing 1 to the enable control appears to not work until the count returns to positive.Change it so that it's impossible for
enable_req_countto be < 0. Return an error to indicate that the disable request was invalid.Fixes 835d722ba10a ("coresight: cti: Initial CoreSight CTI Driver")Tested-by Jinlong Mao <[email protected]>Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-cti-core.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/hwtracing/coresight/coresight-cti-core.c +9
-3@@ -151,9 +151,16 @@ static int cti_disable_hw(struct cti_drvdata *drvdata) {struct cti_config *config = &drvdata->config;struct coresight_device *csdev = drvdata->csdev; +int ret =0 ;spin_lock (&drvdata->spinlock); +/* don't allow negative refcounts, return an error */ +if (!atomic_read (&drvdata->config.enable_req_count)) { + ret = -EINVAL ; + goto cti_not_disabled; + } +/* check refcount - disable on 0 */ if (atomic_dec_return (&drvdata->config.enable_req_count) >0 ) goto cti_not_disabled;@@ -171,12 +178,12 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)coresight_disclaim_device_unlocked (csdev);CS_LOCK (drvdata->base);spin_unlock (&drvdata->spinlock); -return 0 ; +return ret;/* not disabled this call */ cti_not_disabled:spin_unlock (&drvdata->spinlock); -return 0 ; +return ret; }void cti_write_single_reg (struct cti_drvdata *drvdata,int offset,u32 value) --
Quoted 2 lines
2.25.1
Signature · 8 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 2/3 coresight: cti: Add PM runtime call in enable_store
In reply to James ClarkFrom: Mao Jinlong <[email protected]>
In commit 6746eae4bbad ("coresight: cti: Fix hang in cti_disable_hw()") PM runtime calls are removed from cti_enable_hw/cti_disable_hw. When enabling CTI by writing enable sysfs node, clock for accessing CTI register won't be enabled. Device will crash due to register access issue. Add PM runtime call in enable_store to fix this issue.
--- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/hwtracing/coresight/coresight-cti-sysfs.c +11 -2
@@ -108,10 +108,19 @@ static ssize_t enable_store(struct device *dev,if (ret)return ret; -if (val) +if (val) { + ret =pm_runtime_resume_and_get (dev->parent); +if (ret) +return ret; ret =cti_enable (drvdata->csdev); -else +if (ret) +pm_runtime_put (dev->parent); + }else { ret =cti_disable (drvdata->csdev); +if (!ret) +pm_runtime_put (dev->parent); + } +if (ret)return ret;return size;
Signature · 7 lines
2.25.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v3 3/3 coresight: cti: Remove atomic type from enable_req_count
In reply to James Clarkenable_req_count is only ever accessed inside the spinlock, so to avoid confusion that there are concurrent accesses and simplify the code, change it to an int.
One access outside of the spinlock is in enable_show() which appears to allow partially written data to be displayed between enable_req_count, powered and enabled so move this one inside the spin lock too.
--- drivers/hwtracing/coresight/coresight-cti-core.c | 14 +++++++------- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-cti.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/hwtracing/coresight/coresight-cti-core.c +7 -7
@@ -107,12 +107,12 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)cti_write_all_hw_regs (drvdata); config->hw_enabled = true; -atomic_inc (&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++;spin_unlock_irqrestore (&drvdata->spinlock, flags);return rc; cti_state_unchanged: -atomic_inc (&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++;/* cannot enable due to error */ cti_err_not_enabled:
@@ -129,7 +129,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata) config->hw_powered = true;/* no need to do anything if no enable request */ -if (!atomic_read (&drvdata->config.enable_req_count)) +if (!drvdata->config.enable_req_count) goto cti_hp_not_enabled;/* try to claim the device */
@@ -156,13 +156,13 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)spin_lock (&drvdata->spinlock);/* don't allow negative refcounts, return an error */ -if (!atomic_read (&drvdata->config.enable_req_count)) { +if (!drvdata->config.enable_req_count) { ret = -EINVAL ; goto cti_not_disabled; }/* check refcount - disable on 0 */ -if (atomic_dec_return (&drvdata->config.enable_req_count) >0 ) +if (--drvdata->config.enable_req_count >0 ) goto cti_not_disabled;/* no need to do anything if disabled or cpu unpowered */
@@ -239,7 +239,7 @@ static void cti_set_default_config(struct device *dev,/* Most regs default to 0 as zalloc'ed except...*/ config->trig_filter_enable = true; config->ctigate =GENMASK (config->nr_ctm_channels -1 ,0 ); -atomic_set (&config->enable_req_count,0 ); + config->enable_req_count =0 ; }/*
@@ -696,7 +696,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd, drvdata->config.hw_enabled = false;/* check enable reference count to enable HW */ -if (atomic_read (&drvdata->config.enable_req_count)) { +if (drvdata->config.enable_req_count) {/* check we can claim the device as we re-power */ if (coresight_claim_device (csdev)) goto cti_notify_exit;
drivers/hwtracing/coresight/coresight-cti-sysfs.c +1 -1
@@ -84,8 +84,8 @@ static ssize_t enable_show(struct device *dev,bool enabled, powered;struct cti_drvdata *drvdata =dev_get_drvdata (dev->parent); - enable_req =atomic_read (&drvdata->config.enable_req_count);spin_lock (&drvdata->spinlock); + enable_req = drvdata->config.enable_req_count; powered = drvdata->config.hw_powered; enabled = drvdata->config.hw_enabled;spin_unlock (&drvdata->spinlock);
drivers/hwtracing/coresight/coresight-cti.h +1 -1
@@ -141,7 +141,7 @@ struct cti_config {int nr_trig_max;/* cti enable control */ -atomic_t enable_req_count; +int enable_req_count;bool hw_enabled;bool hw_powered;
Signature · 1 line
2.25.1
Re: [PATCH v3 3/3] coresight: cti: Remove atomic type from enable_req_count
Quoted 106 lines · James Clark
enable_req_countis only ever accessed inside the spinlock, so to avoid confusion that there are concurrent accesses and simplify the code, change it to an int.One access outside of the spinlock is in
enable_show()which appears to allow partially written data to be displayed betweenenable_req_count, powered and enabled so move this one inside the spin lock too.Signed-off-by James Clark <[email protected]>--- drivers/hwtracing/coresight/coresight-cti-core.c | 14 +++++++------- drivers/hwtracing/coresight/coresight-cti-sysfs.c | 2 +- drivers/hwtracing/coresight/coresight-cti.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-)drivers/hwtracing/coresight/coresight-cti-core.c +7
-7@@ -107,12 +107,12 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)cti_write_all_hw_regs (drvdata); config->hw_enabled = true; -atomic_inc (&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++;spin_unlock_irqrestore (&drvdata->spinlock, flags);return rc; cti_state_unchanged: -atomic_inc (&drvdata->config.enable_req_count); + drvdata->config.enable_req_count++;/* cannot enable due to error */ cti_err_not_enabled:@@ -129,7 +129,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata) config->hw_powered = true;/* no need to do anything if no enable request */ -if (!atomic_read (&drvdata->config.enable_req_count)) +if (!drvdata->config.enable_req_count) goto cti_hp_not_enabled;/* try to claim the device */ @@ -156,13 +156,13 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)spin_lock (&drvdata->spinlock);/* don't allow negative refcounts, return an error */ -if (!atomic_read (&drvdata->config.enable_req_count)) { +if (!drvdata->config.enable_req_count) { ret = -EINVAL ; goto cti_not_disabled; }/* check refcount - disable on 0 */ -if (atomic_dec_return (&drvdata->config.enable_req_count) >0 ) +if (--drvdata->config.enable_req_count >0 ) goto cti_not_disabled;/* no need to do anything if disabled or cpu unpowered */ @@ -239,7 +239,7 @@ static void cti_set_default_config(struct device *dev,/* Most regs default to 0 as zalloc'ed except...*/ config->trig_filter_enable = true; config->ctigate =GENMASK (config->nr_ctm_channels -1 ,0 ); -atomic_set (&config->enable_req_count,0 ); + config->enable_req_count =0 ; }/* @@ -696,7 +696,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd, drvdata->config.hw_enabled = false;/* check enable reference count to enable HW */ -if (atomic_read (&drvdata->config.enable_req_count)) { +if (drvdata->config.enable_req_count) {/* check we can claim the device as we re-power */ if (coresight_claim_device (csdev)) goto cti_notify_exit;drivers/hwtracing/coresight/coresight-cti-sysfs.c +1
-1@@ -84,8 +84,8 @@ static ssize_t enable_show(struct device *dev,bool enabled, powered;struct cti_drvdata *drvdata =dev_get_drvdata (dev->parent); - enable_req =atomic_read (&drvdata->config.enable_req_count);spin_lock (&drvdata->spinlock); + enable_req = drvdata->config.enable_req_count; powered = drvdata->config.hw_powered; enabled = drvdata->config.hw_enabled;spin_unlock (&drvdata->spinlock);drivers/hwtracing/coresight/coresight-cti.h +1
-2@@ -141,7 +141,7 @@ struct cti_config {int nr_trig_max;/* cti enable control */ -atomic_t enable_req_count; +int enable_req_count;bool hw_enabled;bool hw_powered; --
Quoted 2 lines
2.25.1
Signature · 8 lines
Mike Leach Principal Engineer, ARM Ltd. Manchester Design Centre. UK _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 31 lines · James Clark
Changes since v2:
* Reword first commit message and add fixes tag
* Pickup Jinlong's tested-by tags----
This should be a slight improvement on Jinlong's previous version. Now it's not possible to trigger the error message from
pm_runtime_put()by calling disable twice.It's also similar to the original pre-breaking change version where
pm_runtime_put()was only called if the device was actually disabled, but with one difference: Previouslypm_runtime_put()was only called once for the last disable call, but because of the reference counting inpm_runtime, it should have been called once for each enable call. This meant that the clock would have never been disabled if there were ever multiple enable calls. This is now fixed.The third commit is a refactor and doesn't need to be backported. I removed one of the atomic types because it didn't appear to be required. Maybe it was added for a reason which I'm not aware of, if so it should be pretty easy to drop that change.
James Clark (2):
coresight: cti: Prevent negative values of enable count
coresight: cti: Remove atomic type fromenable_req_countMao Jinlong (1):
coresight: cti: Add PM runtime call inenable_store
Quoted 7 lines
.../hwtracing/coresight/coresight-cti-core.c | 23 ++++++++++++------- .../hwtracing/coresight/coresight-cti-sysfs.c | 15 +++++++++--- drivers/hwtracing/coresight/coresight-cti.h | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-)base-commit:
88603b6dc419445847923fcb7fe5080067a30f98
Queued to coresight next
https://git.kernel.org/coresight/c/479043b77833
Suzuki
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel