Skip to content

Commit 27dc982

Browse files
Tingwei Zhangsmb49
authored andcommitted
coresight: cti: Write regsiters directly in cti_enable_hw()
BugLink: https://bugs.launchpad.net/bugs/1902137 [ Upstream commit 984f37e ] Deadlock as below is triggered by one CPU holds drvdata->spinlock and calls cti_enable_hw(). Smp_call_function_single() is called in cti_enable_hw() and tries to let another CPU write CTI registers. That CPU is trying to get drvdata->spinlock in cti_cpu_pm_notify() and doesn't response to IPI from smp_call_function_single(). [ 988.335937] CPU: 6 PID: 10258 Comm: sh Tainted: G W L 5.8.0-rc6-mainline-16783-gc38daa79b26b-dirty #1 [ 988.346364] Hardware name: Thundercomm Dragonboard 845c (DT) [ 988.352073] pstate: 20400005 (nzCv daif +PAN -UAO BTYPE=--) [ 988.357689] pc : smp_call_function_single+0x158/0x1b8 [ 988.362782] lr : smp_call_function_single+0x124/0x1b8 ... [ 988.451638] Call trace: [ 988.454119] smp_call_function_single+0x158/0x1b8 [ 988.458866] cti_enable+0xb4/0xf8 [coresight_cti] [ 988.463618] coresight_control_assoc_ectdev+0x6c/0x128 [coresight] [ 988.469855] coresight_enable+0x1f0/0x364 [coresight] [ 988.474957] enable_source_store+0x5c/0x9c [coresight] [ 988.480140] dev_attr_store+0x14/0x28 [ 988.483839] sysfs_kf_write+0x38/0x4c [ 988.487532] kernfs_fop_write+0x1c0/0x2b0 [ 988.491585] vfs_write+0xfc/0x300 [ 988.494931] ksys_write+0x78/0xe0 [ 988.498283] __arm64_sys_write+0x18/0x20 [ 988.502240] el0_svc_common+0x98/0x160 [ 988.506024] do_el0_svc+0x78/0x80 [ 988.509377] el0_sync_handler+0xd4/0x270 [ 988.513337] el0_sync+0x164/0x180 This change write CTI registers directly in cti_enable_hw(). Config->hw_powered has been checked to be true with spinlock holded. CTI is powered and can be programmed until spinlock is released. Fixes: 6a0953c ("coresight: cti: Add CPU idle pm notifer to CTI devices") Signed-off-by: Tingwei Zhang <tingwei@codeaurora.org> [Re-ordered variable declaration] Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org> Link: https://lore.kernel.org/r/20200916191737.4001561-10-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Ian May <ian.may@canonical.com>
1 parent 87276bb commit 27dc982

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

drivers/hwtracing/coresight/coresight-cti.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,16 @@ void cti_write_all_hw_regs(struct cti_drvdata *drvdata)
8686
CS_LOCK(drvdata->base);
8787
}
8888

89-
static void cti_enable_hw_smp_call(void *info)
90-
{
91-
struct cti_drvdata *drvdata = info;
92-
93-
cti_write_all_hw_regs(drvdata);
94-
}
95-
9689
/* write regs to hardware and enable */
9790
static int cti_enable_hw(struct cti_drvdata *drvdata)
9891
{
9992
struct cti_config *config = &drvdata->config;
10093
struct device *dev = &drvdata->csdev->dev;
94+
unsigned long flags;
10195
int rc = 0;
10296

10397
pm_runtime_get_sync(dev->parent);
104-
spin_lock(&drvdata->spinlock);
98+
spin_lock_irqsave(&drvdata->spinlock, flags);
10599

106100
/* no need to do anything if enabled or unpowered*/
107101
if (config->hw_enabled || !config->hw_powered)
@@ -112,27 +106,19 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
112106
if (rc)
113107
goto cti_err_not_enabled;
114108

115-
if (drvdata->ctidev.cpu >= 0) {
116-
rc = smp_call_function_single(drvdata->ctidev.cpu,
117-
cti_enable_hw_smp_call,
118-
drvdata, 1);
119-
if (rc)
120-
goto cti_err_not_enabled;
121-
} else {
122-
cti_write_all_hw_regs(drvdata);
123-
}
109+
cti_write_all_hw_regs(drvdata);
124110

125111
config->hw_enabled = true;
126112
atomic_inc(&drvdata->config.enable_req_count);
127-
spin_unlock(&drvdata->spinlock);
113+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
128114
return rc;
129115

130116
cti_state_unchanged:
131117
atomic_inc(&drvdata->config.enable_req_count);
132118

133119
/* cannot enable due to error */
134120
cti_err_not_enabled:
135-
spin_unlock(&drvdata->spinlock);
121+
spin_unlock_irqrestore(&drvdata->spinlock, flags);
136122
pm_runtime_put(dev->parent);
137123
return rc;
138124
}

0 commit comments

Comments
 (0)