Skip to content

Commit e304406

Browse files
LeviYeoReumSuzuki K Poulose
authored andcommitted
coresight-cti: change cti_drvdata spinlock's type to raw_spinlock_t
In coresight-cti drivers, cti_drvdata->spinlock can be held during __schedule() by perf_event_task_sched_out()/in(). Since cti_drvdata->spinlock type is spinlock_t and perf_event_task_sched_out()/in() is called after acquiring rq_lock, which is raw_spinlock_t (an unsleepable lock), this poses an issue in PREEMPT_RT kernel where spinlock_t is sleepable. To address this, change type cti_drvdata->spinlock in coresight-cti drivers, which can be called by perf_event_task_sched_out()/in(), from spinlock_t to raw_spinlock_t. Reviewed-by: James Clark <james.clark@linaro.org> Reviewed-by: Mike Leach <mike.leach@linaro.org> Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> Link: https://lore.kernel.org/r/20250306121110.1647948-5-yeoreum.yun@arm.com
1 parent 4cf364c commit e304406

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

drivers/hwtracing/coresight/coresight-cti-core.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
9393
unsigned long flags;
9494
int rc = 0;
9595

96-
spin_lock_irqsave(&drvdata->spinlock, flags);
96+
raw_spin_lock_irqsave(&drvdata->spinlock, flags);
9797

9898
/* no need to do anything if enabled or unpowered*/
9999
if (config->hw_enabled || !config->hw_powered)
@@ -108,15 +108,15 @@ static int cti_enable_hw(struct cti_drvdata *drvdata)
108108

109109
config->hw_enabled = true;
110110
drvdata->config.enable_req_count++;
111-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
111+
raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
112112
return rc;
113113

114114
cti_state_unchanged:
115115
drvdata->config.enable_req_count++;
116116

117117
/* cannot enable due to error */
118118
cti_err_not_enabled:
119-
spin_unlock_irqrestore(&drvdata->spinlock, flags);
119+
raw_spin_unlock_irqrestore(&drvdata->spinlock, flags);
120120
return rc;
121121
}
122122

@@ -125,7 +125,7 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
125125
{
126126
struct cti_config *config = &drvdata->config;
127127

128-
spin_lock(&drvdata->spinlock);
128+
raw_spin_lock(&drvdata->spinlock);
129129
config->hw_powered = true;
130130

131131
/* no need to do anything if no enable request */
@@ -138,12 +138,12 @@ static void cti_cpuhp_enable_hw(struct cti_drvdata *drvdata)
138138

139139
cti_write_all_hw_regs(drvdata);
140140
config->hw_enabled = true;
141-
spin_unlock(&drvdata->spinlock);
141+
raw_spin_unlock(&drvdata->spinlock);
142142
return;
143143

144144
/* did not re-enable due to no claim / no request */
145145
cti_hp_not_enabled:
146-
spin_unlock(&drvdata->spinlock);
146+
raw_spin_unlock(&drvdata->spinlock);
147147
}
148148

149149
/* disable hardware */
@@ -153,7 +153,7 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)
153153
struct coresight_device *csdev = drvdata->csdev;
154154
int ret = 0;
155155

156-
spin_lock(&drvdata->spinlock);
156+
raw_spin_lock(&drvdata->spinlock);
157157

158158
/* don't allow negative refcounts, return an error */
159159
if (!drvdata->config.enable_req_count) {
@@ -177,12 +177,12 @@ static int cti_disable_hw(struct cti_drvdata *drvdata)
177177

178178
coresight_disclaim_device_unlocked(csdev);
179179
CS_LOCK(drvdata->base);
180-
spin_unlock(&drvdata->spinlock);
180+
raw_spin_unlock(&drvdata->spinlock);
181181
return ret;
182182

183183
/* not disabled this call */
184184
cti_not_disabled:
185-
spin_unlock(&drvdata->spinlock);
185+
raw_spin_unlock(&drvdata->spinlock);
186186
return ret;
187187
}
188188

@@ -198,11 +198,11 @@ void cti_write_intack(struct device *dev, u32 ackval)
198198
struct cti_drvdata *drvdata = dev_get_drvdata(dev->parent);
199199
struct cti_config *config = &drvdata->config;
200200

201-
spin_lock(&drvdata->spinlock);
201+
raw_spin_lock(&drvdata->spinlock);
202202
/* write if enabled */
203203
if (cti_active(config))
204204
cti_write_single_reg(drvdata, CTIINTACK, ackval);
205-
spin_unlock(&drvdata->spinlock);
205+
raw_spin_unlock(&drvdata->spinlock);
206206
}
207207

208208
/*
@@ -369,7 +369,7 @@ int cti_channel_trig_op(struct device *dev, enum cti_chan_op op,
369369
reg_offset = (direction == CTI_TRIG_IN ? CTIINEN(trigger_idx) :
370370
CTIOUTEN(trigger_idx));
371371

372-
spin_lock(&drvdata->spinlock);
372+
raw_spin_lock(&drvdata->spinlock);
373373

374374
/* read - modify write - the trigger / channel enable value */
375375
reg_value = direction == CTI_TRIG_IN ? config->ctiinen[trigger_idx] :
@@ -388,7 +388,7 @@ int cti_channel_trig_op(struct device *dev, enum cti_chan_op op,
388388
/* write through if enabled */
389389
if (cti_active(config))
390390
cti_write_single_reg(drvdata, reg_offset, reg_value);
391-
spin_unlock(&drvdata->spinlock);
391+
raw_spin_unlock(&drvdata->spinlock);
392392
return 0;
393393
}
394394

@@ -406,7 +406,7 @@ int cti_channel_gate_op(struct device *dev, enum cti_chan_gate_op op,
406406

407407
chan_bitmask = BIT(channel_idx);
408408

409-
spin_lock(&drvdata->spinlock);
409+
raw_spin_lock(&drvdata->spinlock);
410410
reg_value = config->ctigate;
411411
switch (op) {
412412
case CTI_GATE_CHAN_ENABLE:
@@ -426,7 +426,7 @@ int cti_channel_gate_op(struct device *dev, enum cti_chan_gate_op op,
426426
if (cti_active(config))
427427
cti_write_single_reg(drvdata, CTIGATE, reg_value);
428428
}
429-
spin_unlock(&drvdata->spinlock);
429+
raw_spin_unlock(&drvdata->spinlock);
430430
return err;
431431
}
432432

@@ -445,7 +445,7 @@ int cti_channel_setop(struct device *dev, enum cti_chan_set_op op,
445445

446446
chan_bitmask = BIT(channel_idx);
447447

448-
spin_lock(&drvdata->spinlock);
448+
raw_spin_lock(&drvdata->spinlock);
449449
reg_value = config->ctiappset;
450450
switch (op) {
451451
case CTI_CHAN_SET:
@@ -473,7 +473,7 @@ int cti_channel_setop(struct device *dev, enum cti_chan_set_op op,
473473

474474
if ((err == 0) && cti_active(config))
475475
cti_write_single_reg(drvdata, reg_offset, reg_value);
476-
spin_unlock(&drvdata->spinlock);
476+
raw_spin_unlock(&drvdata->spinlock);
477477

478478
return err;
479479
}
@@ -676,7 +676,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
676676
if (WARN_ON_ONCE(drvdata->ctidev.cpu != cpu))
677677
return NOTIFY_BAD;
678678

679-
spin_lock(&drvdata->spinlock);
679+
raw_spin_lock(&drvdata->spinlock);
680680

681681
switch (cmd) {
682682
case CPU_PM_ENTER:
@@ -716,7 +716,7 @@ static int cti_cpu_pm_notify(struct notifier_block *nb, unsigned long cmd,
716716
}
717717

718718
cti_notify_exit:
719-
spin_unlock(&drvdata->spinlock);
719+
raw_spin_unlock(&drvdata->spinlock);
720720
return notify_res;
721721
}
722722

@@ -743,11 +743,11 @@ static int cti_dying_cpu(unsigned int cpu)
743743
if (!drvdata)
744744
return 0;
745745

746-
spin_lock(&drvdata->spinlock);
746+
raw_spin_lock(&drvdata->spinlock);
747747
drvdata->config.hw_powered = false;
748748
if (drvdata->config.hw_enabled)
749749
coresight_disclaim_device(drvdata->csdev);
750-
spin_unlock(&drvdata->spinlock);
750+
raw_spin_unlock(&drvdata->spinlock);
751751
return 0;
752752
}
753753

@@ -888,7 +888,7 @@ static int cti_probe(struct amba_device *adev, const struct amba_id *id)
888888
drvdata->ctidev.ctm_id = 0;
889889
INIT_LIST_HEAD(&drvdata->ctidev.trig_cons);
890890

891-
spin_lock_init(&drvdata->spinlock);
891+
raw_spin_lock_init(&drvdata->spinlock);
892892

893893
/* initialise CTI driver config values */
894894
cti_set_default_config(dev, drvdata);

0 commit comments

Comments
 (0)