Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
39c715b7 IM |
2 | /* |
3 | * lib/smp_processor_id.c | |
4 | * | |
5 | * DEBUG_PREEMPT variant of smp_processor_id(). | |
6 | */ | |
8bc3bcc9 | 7 | #include <linux/export.h> |
984640ce | 8 | #include <linux/kprobes.h> |
4e57b681 | 9 | #include <linux/sched.h> |
39c715b7 | 10 | |
126f21f0 | 11 | noinstr static |
984640ce | 12 | unsigned int check_preemption_disabled(const char *what1, const char *what2) |
39c715b7 | 13 | { |
39c715b7 | 14 | int this_cpu = raw_smp_processor_id(); |
39c715b7 | 15 | |
4a2b4b22 | 16 | if (likely(preempt_count())) |
39c715b7 IM |
17 | goto out; |
18 | ||
19 | if (irqs_disabled()) | |
20 | goto out; | |
21 | ||
570a752b | 22 | if (is_percpu_thread()) |
39c715b7 IM |
23 | goto out; |
24 | ||
74d862b6 | 25 | #ifdef CONFIG_SMP |
af449901 PZ |
26 | if (current->migration_disabled) |
27 | goto out; | |
28 | #endif | |
29 | ||
39c715b7 IM |
30 | /* |
31 | * It is valid to assume CPU-locality during early bootup: | |
32 | */ | |
1c3c5eab | 33 | if (system_state < SYSTEM_SCHEDULING) |
39c715b7 IM |
34 | goto out; |
35 | ||
36 | /* | |
37 | * Avoid recursion: | |
38 | */ | |
5568b139 | 39 | preempt_disable_notrace(); |
39c715b7 | 40 | |
126f21f0 | 41 | instrumentation_begin(); |
39c715b7 IM |
42 | if (!printk_ratelimit()) |
43 | goto out_enable; | |
44 | ||
188a8140 CL |
45 | printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n", |
46 | what1, what2, preempt_count() - 1, current->comm, current->pid); | |
47 | ||
d202d47b | 48 | printk("caller is %pS\n", __builtin_return_address(0)); |
39c715b7 IM |
49 | dump_stack(); |
50 | ||
51 | out_enable: | |
bd27acaa | 52 | instrumentation_end(); |
5568b139 | 53 | preempt_enable_no_resched_notrace(); |
39c715b7 IM |
54 | out: |
55 | return this_cpu; | |
56 | } | |
57 | ||
126f21f0 | 58 | noinstr unsigned int debug_smp_processor_id(void) |
188a8140 CL |
59 | { |
60 | return check_preemption_disabled("smp_processor_id", ""); | |
61 | } | |
39c715b7 IM |
62 | EXPORT_SYMBOL(debug_smp_processor_id); |
63 | ||
126f21f0 | 64 | noinstr void __this_cpu_preempt_check(const char *op) |
188a8140 CL |
65 | { |
66 | check_preemption_disabled("__this_cpu_", op); | |
67 | } | |
68 | EXPORT_SYMBOL(__this_cpu_preempt_check); |