Commit b841128
coresight: ultrasoc-smb: Fix sleep while close preempt in enable_smb
When we to enable the SMB by perf, the perf sched will call perf_ctx_lock()
to close system preempt in event_function_call(). But SMB::enable_smb() use
mutex to lock the critical section, which may sleep.
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580
in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 153023, name: perf
preempt_count: 2, expected: 0
RCU nest depth: 0, expected: 0
INFO: lockdep is turned off.
irq event stamp: 0
hardirqs last enabled at (0): [<0000000000000000>] 0x0
hardirqs last disabled at (0): [<ffffa2983f5c5f40>] copy_process+0xae8/0x2b48
softirqs last enabled at (0): [<ffffa2983f5c5f40>] copy_process+0xae8/0x2b48
softirqs last disabled at (0): [<0000000000000000>] 0x0
CPU: 2 PID: 153023 Comm: perf Kdump: loaded Tainted: G W O 6.5.0-rc4+ #1
Call trace:
...
__mutex_lock+0xbc/0xa70
mutex_lock_nested+0x34/0x48
smb_update_buffer+0x58/0x360 [ultrasoc_smb]
etm_event_stop+0x204/0x2d8 [coresight]
etm_event_del+0x1c/0x30 [coresight]
event_sched_out+0x17c/0x3b8
group_sched_out.part.0+0x5c/0x208
__perf_event_disable+0x15c/0x210
event_function+0xe0/0x230
remote_function+0xb4/0xe8
generic_exec_single+0x160/0x268
smp_call_function_single+0x20c/0x2a0
event_function_call+0x20c/0x220
_perf_event_disable+0x5c/0x90
perf_event_for_each_child+0x58/0xc0
_perf_ioctl+0x34c/0x1250
perf_ioctl+0x64/0x98
...
Use spinlock to replace mutex to control driver data access to one at a
time. The function copy_to_user() may sleep, it cannot be in a spinlock
context, so we can't simply replace it in smb_read(). But we can ensure
that only one user gets the SMB device fd by smb_open(), so remove the
locks from smb_read() and buffer synchronization is guaranteed by the user.
Fixes: 06f5c29 ("drivers/coresight: Add UltraSoc System Memory Buffer driver")
Signed-off-by: Junhao He <hejunhao3@huawei.com>
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://lore.kernel.org/r/20231114133346.30489-2-hejunhao3@huawei.com1 parent e49c0b1 commit b841128
2 files changed
Lines changed: 17 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
| 102 | + | |
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
| 118 | + | |
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| |||
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
135 | | - | |
136 | | - | |
137 | 135 | | |
138 | | - | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
| |||
145 | 143 | | |
146 | 144 | | |
147 | 145 | | |
148 | | - | |
149 | | - | |
| 146 | + | |
150 | 147 | | |
151 | 148 | | |
152 | 149 | | |
153 | | - | |
154 | 150 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | 151 | | |
159 | 152 | | |
160 | | - | |
161 | 153 | | |
| 154 | + | |
162 | 155 | | |
163 | 156 | | |
164 | 157 | | |
| |||
167 | 160 | | |
168 | 161 | | |
169 | 162 | | |
170 | | - | |
| 163 | + | |
171 | 164 | | |
172 | | - | |
| 165 | + | |
173 | 166 | | |
174 | 167 | | |
175 | 168 | | |
| |||
262 | 255 | | |
263 | 256 | | |
264 | 257 | | |
265 | | - | |
| 258 | + | |
266 | 259 | | |
267 | 260 | | |
268 | 261 | | |
| |||
294 | 287 | | |
295 | 288 | | |
296 | 289 | | |
297 | | - | |
| 290 | + | |
298 | 291 | | |
299 | 292 | | |
300 | 293 | | |
| |||
304 | 297 | | |
305 | 298 | | |
306 | 299 | | |
307 | | - | |
| 300 | + | |
308 | 301 | | |
309 | 302 | | |
310 | 303 | | |
| |||
327 | 320 | | |
328 | 321 | | |
329 | 322 | | |
330 | | - | |
| 323 | + | |
331 | 324 | | |
332 | 325 | | |
333 | 326 | | |
| |||
408 | 401 | | |
409 | 402 | | |
410 | 403 | | |
411 | | - | |
| 404 | + | |
412 | 405 | | |
413 | 406 | | |
414 | 407 | | |
| |||
432 | 425 | | |
433 | 426 | | |
434 | 427 | | |
435 | | - | |
| 428 | + | |
436 | 429 | | |
437 | 430 | | |
438 | 431 | | |
| |||
590 | 583 | | |
591 | 584 | | |
592 | 585 | | |
593 | | - | |
| 586 | + | |
594 | 587 | | |
595 | 588 | | |
596 | 589 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
0 commit comments