smp_processor_id.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * lib/smp_processor_id.c
  4. *
  5. * DEBUG_PREEMPT variant of smp_processor_id().
  6. */
  7. #include <linux/export.h>
  8. #include <linux/kprobes.h>
  9. #include <linux/sched.h>
  10. noinstr static
  11. unsigned int check_preemption_disabled(const char *what1, const char *what2)
  12. {
  13. int this_cpu = raw_smp_processor_id();
  14. if (likely(preempt_count()))
  15. goto out;
  16. if (irqs_disabled())
  17. goto out;
  18. if (is_percpu_thread())
  19. goto out;
  20. #ifdef CONFIG_SMP
  21. if (current->migration_disabled)
  22. goto out;
  23. #endif
  24. /*
  25. * It is valid to assume CPU-locality during early bootup:
  26. */
  27. if (system_state < SYSTEM_SCHEDULING)
  28. goto out;
  29. /*
  30. * Avoid recursion:
  31. */
  32. preempt_disable_notrace();
  33. instrumentation_begin();
  34. if (!printk_ratelimit())
  35. goto out_enable;
  36. printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
  37. what1, what2, preempt_count() - 1, current->comm, current->pid);
  38. printk("caller is %pS\n", __builtin_return_address(0));
  39. dump_stack();
  40. out_enable:
  41. instrumentation_end();
  42. preempt_enable_no_resched_notrace();
  43. out:
  44. return this_cpu;
  45. }
  46. noinstr unsigned int debug_smp_processor_id(void)
  47. {
  48. return check_preemption_disabled("smp_processor_id", "");
  49. }
  50. EXPORT_SYMBOL(debug_smp_processor_id);
  51. noinstr void __this_cpu_preempt_check(const char *op)
  52. {
  53. check_preemption_disabled("__this_cpu_", op);
  54. }
  55. EXPORT_SYMBOL(__this_cpu_preempt_check);