Skip to content

Commit 35049a4

Browse files
Sai Prakash Ranjanintel-lab-lkp
authored andcommitted
coresight: tmc: Read TMC mode only when TMC hw is enabled
Reading TMC mode register in tmc_read_prepare_etb without enabling the TMC hardware leads to async exceptions like the one in the call trace below. This can happen if the user tries to read the TMC etf data via device node without setting up source and the sink first which enables the TMC hardware in the path. So make sure that the TMC is enabled before we try to read TMC data. Kernel panic - not syncing: Asynchronous SError Interrupt CPU: 7 PID: 2605 Comm: hexdump Tainted: G S 5.4.30 torvalds#122 Call trace: dump_backtrace+0x0/0x188 show_stack+0x20/0x2c dump_stack+0xdc/0x144 panic+0x168/0x36c panic+0x0/0x36c arm64_serror_panic+0x78/0x84 do_serror+0x130/0x138 el1_error+0x84/0xf8 tmc_read_prepare_etb+0x88/0xb8 tmc_open+0x40/0xd8 misc_open+0x120/0x158 chrdev_open+0xb8/0x1a4 do_dentry_open+0x268/0x3a0 vfs_open+0x34/0x40 path_openat+0x39c/0xdf4 do_filp_open+0x90/0x10c do_sys_open+0x150/0x3e8 __arm64_compat_sys_openat+0x28/0x34 el0_svc_common+0xa8/0x160 el0_svc_compat_handler+0x2c/0x38 el0_svc_compat+0x8/0x10 Fixes: 4525412 ("coresight: tmc: making prepare/unprepare functions generic") Reported-by: Stephen Boyd <[email protected]> Signed-off-by: Sai Prakash Ranjan <[email protected]>
1 parent 5d30bca commit 35049a4

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

drivers/hwtracing/coresight/coresight-tmc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,13 @@ void tmc_flush_and_stop(struct tmc_drvdata *drvdata)
6262

6363
void tmc_enable_hw(struct tmc_drvdata *drvdata)
6464
{
65+
drvdata->enable = true;
6566
writel_relaxed(TMC_CTL_CAPT_EN, drvdata->base + TMC_CTL);
6667
}
6768

6869
void tmc_disable_hw(struct tmc_drvdata *drvdata)
6970
{
71+
drvdata->enable = false;
7072
writel_relaxed(0x0, drvdata->base + TMC_CTL);
7173
}
7274

@@ -102,6 +104,9 @@ static int tmc_read_prepare(struct tmc_drvdata *drvdata)
102104
{
103105
int ret = 0;
104106

107+
if (!drvdata->enable)
108+
return -EINVAL;
109+
105110
switch (drvdata->config_type) {
106111
case TMC_CONFIG_TYPE_ETB:
107112
case TMC_CONFIG_TYPE_ETF:

drivers/hwtracing/coresight/coresight-tmc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ struct tmc_drvdata {
191191
struct miscdevice miscdev;
192192
spinlock_t spinlock;
193193
pid_t pid;
194+
bool enable;
194195
bool reading;
195196
union {
196197
char *buf; /* TMC ETB */

0 commit comments

Comments
 (0)