Commit 10bfb77
LoongArch: Fix calling smp_processor_id() in preemptible code
Fix the warning:
BUG: using smp_processor_id() in preemptible [00000000] code: sys
temd/1
caller is larch_insn_text_copy+0x40/0xf0
Simply changing it to raw_smp_processor_id() is not enough: if preempt
and CPU hotplug happens after raw_smp_processor_id() but before
stop_machine(), the CPU where raw_smp_processor_id() has run may be
offline when stop_machine() and no CPU will run copy_to_kernel_nofault()
in text_copy_cb(). Thus guard the larch_insn_text_copy() calls with
cpus_read_lock() and change stop_machine() to stop_machine_cpuslocked()
to prevent this.
I've considered moving the locks inside larch_insn_text_copy() but
doing so seems not an easy hack. In bpf_arch_text_poke() obviously the
memcpy() call must be guarded by text_mutex, so we have to leave the
acquire of text_mutex out of larch_insn_text_copy. But in the entire
kernel the acquire of mutexes is always after cpus_read_lock(), so we
cannot put cpus_read_lock() into larch_insn_text_copy() while leaving
the text_mutex acquire out (or we risk a deadlock due to inconsistent
lock acquire order). So let's fix the bug first and leave the
posssible refactor as future work.
Fixes: 9fbd18c ("LoongArch: BPF: Add dynamic code modification support")
Signed-off-by: Xi Ruoyao <xry111@xry111.site>1 parent ebefa82 commit 10bfb77
2 files changed
+14
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
266 | | - | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
269 | 275 | | |
270 | 276 | | |
271 | 277 | | |
272 | 278 | | |
273 | | - | |
| 279 | + | |
274 | 280 | | |
275 | 281 | | |
276 | 282 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1379 | 1379 | | |
1380 | 1380 | | |
1381 | 1381 | | |
| 1382 | + | |
1382 | 1383 | | |
1383 | 1384 | | |
1384 | 1385 | | |
| 1386 | + | |
1385 | 1387 | | |
1386 | 1388 | | |
1387 | 1389 | | |
| |||
1429 | 1431 | | |
1430 | 1432 | | |
1431 | 1433 | | |
| 1434 | + | |
1432 | 1435 | | |
1433 | 1436 | | |
1434 | 1437 | | |
1435 | 1438 | | |
| 1439 | + | |
1436 | 1440 | | |
1437 | 1441 | | |
1438 | 1442 | | |
| |||
1450 | 1454 | | |
1451 | 1455 | | |
1452 | 1456 | | |
| 1457 | + | |
1453 | 1458 | | |
1454 | 1459 | | |
1455 | 1460 | | |
1456 | 1461 | | |
| 1462 | + | |
1457 | 1463 | | |
1458 | 1464 | | |
1459 | 1465 | | |
| |||
0 commit comments