alternative.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. #include <linux/module.h>
  2. #include <linux/sched.h>
  3. #include <linux/mutex.h>
  4. #include <linux/list.h>
  5. #include <linux/stringify.h>
  6. #include <linux/kprobes.h>
  7. #include <linux/mm.h>
  8. #include <linux/vmalloc.h>
  9. #include <linux/memory.h>
  10. #include <linux/stop_machine.h>
  11. #include <asm/alternative.h>
  12. #include <asm/sections.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/mce.h>
  15. #include <asm/nmi.h>
  16. #include <asm/vsyscall.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/tlbflush.h>
  19. #include <asm/io.h>
  20. #include <asm/fixmap.h>
  21. #define MAX_PATCH_LEN (255-1)
  22. #ifdef CONFIG_HOTPLUG_CPU
  23. static int smp_alt_once;
  24. static int __init bootonly(char *str)
  25. {
  26. smp_alt_once = 1;
  27. return 1;
  28. }
  29. __setup("smp-alt-boot", bootonly);
  30. #else
  31. #define smp_alt_once 1
  32. #endif
  33. static int __initdata_or_module debug_alternative;
  34. static int __init debug_alt(char *str)
  35. {
  36. debug_alternative = 1;
  37. return 1;
  38. }
  39. __setup("debug-alternative", debug_alt);
  40. static int noreplace_smp;
  41. static int __init setup_noreplace_smp(char *str)
  42. {
  43. noreplace_smp = 1;
  44. return 1;
  45. }
  46. __setup("noreplace-smp", setup_noreplace_smp);
  47. #ifdef CONFIG_PARAVIRT
  48. static int __initdata_or_module noreplace_paravirt = 0;
  49. static int __init setup_noreplace_paravirt(char *str)
  50. {
  51. noreplace_paravirt = 1;
  52. return 1;
  53. }
  54. __setup("noreplace-paravirt", setup_noreplace_paravirt);
  55. #endif
  56. #define DPRINTK(fmt, args...) if (debug_alternative) \
  57. printk(KERN_DEBUG fmt, args)
  58. #if defined(GENERIC_NOP1) && !defined(CONFIG_X86_64)
  59. /* Use inline assembly to define this because the nops are defined
  60. as inline assembly strings in the include files and we cannot
  61. get them easily into strings. */
  62. asm("\t" __stringify(__INITRODATA_OR_MODULE) "\nintelnops: "
  63. GENERIC_NOP1 GENERIC_NOP2 GENERIC_NOP3 GENERIC_NOP4 GENERIC_NOP5 GENERIC_NOP6
  64. GENERIC_NOP7 GENERIC_NOP8
  65. "\t.previous");
  66. extern const unsigned char intelnops[];
  67. static const unsigned char *const __initconst_or_module
  68. intel_nops[ASM_NOP_MAX+1] = {
  69. NULL,
  70. intelnops,
  71. intelnops + 1,
  72. intelnops + 1 + 2,
  73. intelnops + 1 + 2 + 3,
  74. intelnops + 1 + 2 + 3 + 4,
  75. intelnops + 1 + 2 + 3 + 4 + 5,
  76. intelnops + 1 + 2 + 3 + 4 + 5 + 6,
  77. intelnops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  78. };
  79. #endif
  80. #ifdef K8_NOP1
  81. asm("\t" __stringify(__INITRODATA_OR_MODULE) "\nk8nops: "
  82. K8_NOP1 K8_NOP2 K8_NOP3 K8_NOP4 K8_NOP5 K8_NOP6
  83. K8_NOP7 K8_NOP8
  84. "\t.previous");
  85. extern const unsigned char k8nops[];
  86. static const unsigned char *const __initconst_or_module
  87. k8_nops[ASM_NOP_MAX+1] = {
  88. NULL,
  89. k8nops,
  90. k8nops + 1,
  91. k8nops + 1 + 2,
  92. k8nops + 1 + 2 + 3,
  93. k8nops + 1 + 2 + 3 + 4,
  94. k8nops + 1 + 2 + 3 + 4 + 5,
  95. k8nops + 1 + 2 + 3 + 4 + 5 + 6,
  96. k8nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  97. };
  98. #endif
  99. #if defined(K7_NOP1) && !defined(CONFIG_X86_64)
  100. asm("\t" __stringify(__INITRODATA_OR_MODULE) "\nk7nops: "
  101. K7_NOP1 K7_NOP2 K7_NOP3 K7_NOP4 K7_NOP5 K7_NOP6
  102. K7_NOP7 K7_NOP8
  103. "\t.previous");
  104. extern const unsigned char k7nops[];
  105. static const unsigned char *const __initconst_or_module
  106. k7_nops[ASM_NOP_MAX+1] = {
  107. NULL,
  108. k7nops,
  109. k7nops + 1,
  110. k7nops + 1 + 2,
  111. k7nops + 1 + 2 + 3,
  112. k7nops + 1 + 2 + 3 + 4,
  113. k7nops + 1 + 2 + 3 + 4 + 5,
  114. k7nops + 1 + 2 + 3 + 4 + 5 + 6,
  115. k7nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  116. };
  117. #endif
  118. #ifdef P6_NOP1
  119. asm("\t" __stringify(__INITRODATA_OR_MODULE) "\np6nops: "
  120. P6_NOP1 P6_NOP2 P6_NOP3 P6_NOP4 P6_NOP5 P6_NOP6
  121. P6_NOP7 P6_NOP8
  122. "\t.previous");
  123. extern const unsigned char p6nops[];
  124. static const unsigned char *const __initconst_or_module
  125. p6_nops[ASM_NOP_MAX+1] = {
  126. NULL,
  127. p6nops,
  128. p6nops + 1,
  129. p6nops + 1 + 2,
  130. p6nops + 1 + 2 + 3,
  131. p6nops + 1 + 2 + 3 + 4,
  132. p6nops + 1 + 2 + 3 + 4 + 5,
  133. p6nops + 1 + 2 + 3 + 4 + 5 + 6,
  134. p6nops + 1 + 2 + 3 + 4 + 5 + 6 + 7,
  135. };
  136. #endif
  137. #ifdef CONFIG_X86_64
  138. extern char __vsyscall_0;
  139. static const unsigned char *const *__init_or_module find_nop_table(void)
  140. {
  141. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  142. boot_cpu_has(X86_FEATURE_NOPL))
  143. return p6_nops;
  144. else
  145. return k8_nops;
  146. }
  147. #else /* CONFIG_X86_64 */
  148. static const unsigned char *const *__init_or_module find_nop_table(void)
  149. {
  150. if (boot_cpu_has(X86_FEATURE_K8))
  151. return k8_nops;
  152. else if (boot_cpu_has(X86_FEATURE_K7))
  153. return k7_nops;
  154. else if (boot_cpu_has(X86_FEATURE_NOPL))
  155. return p6_nops;
  156. else
  157. return intel_nops;
  158. }
  159. #endif /* CONFIG_X86_64 */
  160. /* Use this to add nops to a buffer, then text_poke the whole buffer. */
  161. static void __init_or_module add_nops(void *insns, unsigned int len)
  162. {
  163. const unsigned char *const *noptable = find_nop_table();
  164. while (len > 0) {
  165. unsigned int noplen = len;
  166. if (noplen > ASM_NOP_MAX)
  167. noplen = ASM_NOP_MAX;
  168. memcpy(insns, noptable[noplen], noplen);
  169. insns += noplen;
  170. len -= noplen;
  171. }
  172. }
  173. extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
  174. extern u8 *__smp_locks[], *__smp_locks_end[];
  175. static void *text_poke_early(void *addr, const void *opcode, size_t len);
  176. /* Replace instructions with better alternatives for this CPU type.
  177. This runs before SMP is initialized to avoid SMP problems with
  178. self modifying code. This implies that assymetric systems where
  179. APs have less capabilities than the boot processor are not handled.
  180. Tough. Make sure you disable such features by hand. */
  181. void __init_or_module apply_alternatives(struct alt_instr *start,
  182. struct alt_instr *end)
  183. {
  184. struct alt_instr *a;
  185. u8 insnbuf[MAX_PATCH_LEN];
  186. DPRINTK("%s: alt table %p -> %p\n", __func__, start, end);
  187. for (a = start; a < end; a++) {
  188. u8 *instr = a->instr;
  189. BUG_ON(a->replacementlen > a->instrlen);
  190. BUG_ON(a->instrlen > sizeof(insnbuf));
  191. if (!boot_cpu_has(a->cpuid))
  192. continue;
  193. #ifdef CONFIG_X86_64
  194. /* vsyscall code is not mapped yet. resolve it manually. */
  195. if (instr >= (u8 *)VSYSCALL_START && instr < (u8*)VSYSCALL_END) {
  196. instr = __va(instr - (u8*)VSYSCALL_START + (u8*)__pa_symbol(&__vsyscall_0));
  197. DPRINTK("%s: vsyscall fixup: %p => %p\n",
  198. __func__, a->instr, instr);
  199. }
  200. #endif
  201. memcpy(insnbuf, a->replacement, a->replacementlen);
  202. if (*insnbuf == 0xe8 && a->replacementlen == 5)
  203. *(s32 *)(insnbuf + 1) += a->replacement - a->instr;
  204. add_nops(insnbuf + a->replacementlen,
  205. a->instrlen - a->replacementlen);
  206. text_poke_early(instr, insnbuf, a->instrlen);
  207. }
  208. }
  209. #ifdef CONFIG_SMP
  210. static void alternatives_smp_lock(u8 **start, u8 **end, u8 *text, u8 *text_end)
  211. {
  212. u8 **ptr;
  213. mutex_lock(&text_mutex);
  214. for (ptr = start; ptr < end; ptr++) {
  215. if (*ptr < text)
  216. continue;
  217. if (*ptr > text_end)
  218. continue;
  219. /* turn DS segment override prefix into lock prefix */
  220. text_poke(*ptr, ((unsigned char []){0xf0}), 1);
  221. };
  222. mutex_unlock(&text_mutex);
  223. }
  224. static void alternatives_smp_unlock(u8 **start, u8 **end, u8 *text, u8 *text_end)
  225. {
  226. u8 **ptr;
  227. if (noreplace_smp)
  228. return;
  229. mutex_lock(&text_mutex);
  230. for (ptr = start; ptr < end; ptr++) {
  231. if (*ptr < text)
  232. continue;
  233. if (*ptr > text_end)
  234. continue;
  235. /* turn lock prefix into DS segment override prefix */
  236. text_poke(*ptr, ((unsigned char []){0x3E}), 1);
  237. };
  238. mutex_unlock(&text_mutex);
  239. }
  240. struct smp_alt_module {
  241. /* what is this ??? */
  242. struct module *mod;
  243. char *name;
  244. /* ptrs to lock prefixes */
  245. u8 **locks;
  246. u8 **locks_end;
  247. /* .text segment, needed to avoid patching init code ;) */
  248. u8 *text;
  249. u8 *text_end;
  250. struct list_head next;
  251. };
  252. static LIST_HEAD(smp_alt_modules);
  253. static DEFINE_MUTEX(smp_alt);
  254. static int smp_mode = 1; /* protected by smp_alt */
  255. void __init_or_module alternatives_smp_module_add(struct module *mod,
  256. char *name,
  257. void *locks, void *locks_end,
  258. void *text, void *text_end)
  259. {
  260. struct smp_alt_module *smp;
  261. if (noreplace_smp)
  262. return;
  263. if (smp_alt_once) {
  264. if (boot_cpu_has(X86_FEATURE_UP))
  265. alternatives_smp_unlock(locks, locks_end,
  266. text, text_end);
  267. return;
  268. }
  269. smp = kzalloc(sizeof(*smp), GFP_KERNEL);
  270. if (NULL == smp)
  271. return; /* we'll run the (safe but slow) SMP code then ... */
  272. smp->mod = mod;
  273. smp->name = name;
  274. smp->locks = locks;
  275. smp->locks_end = locks_end;
  276. smp->text = text;
  277. smp->text_end = text_end;
  278. DPRINTK("%s: locks %p -> %p, text %p -> %p, name %s\n",
  279. __func__, smp->locks, smp->locks_end,
  280. smp->text, smp->text_end, smp->name);
  281. mutex_lock(&smp_alt);
  282. list_add_tail(&smp->next, &smp_alt_modules);
  283. if (boot_cpu_has(X86_FEATURE_UP))
  284. alternatives_smp_unlock(smp->locks, smp->locks_end,
  285. smp->text, smp->text_end);
  286. mutex_unlock(&smp_alt);
  287. }
  288. void __init_or_module alternatives_smp_module_del(struct module *mod)
  289. {
  290. struct smp_alt_module *item;
  291. if (smp_alt_once || noreplace_smp)
  292. return;
  293. mutex_lock(&smp_alt);
  294. list_for_each_entry(item, &smp_alt_modules, next) {
  295. if (mod != item->mod)
  296. continue;
  297. list_del(&item->next);
  298. mutex_unlock(&smp_alt);
  299. DPRINTK("%s: %s\n", __func__, item->name);
  300. kfree(item);
  301. return;
  302. }
  303. mutex_unlock(&smp_alt);
  304. }
  305. void alternatives_smp_switch(int smp)
  306. {
  307. struct smp_alt_module *mod;
  308. #ifdef CONFIG_LOCKDEP
  309. /*
  310. * Older binutils section handling bug prevented
  311. * alternatives-replacement from working reliably.
  312. *
  313. * If this still occurs then you should see a hang
  314. * or crash shortly after this line:
  315. */
  316. printk("lockdep: fixing up alternatives.\n");
  317. #endif
  318. if (noreplace_smp || smp_alt_once)
  319. return;
  320. BUG_ON(!smp && (num_online_cpus() > 1));
  321. mutex_lock(&smp_alt);
  322. /*
  323. * Avoid unnecessary switches because it forces JIT based VMs to
  324. * throw away all cached translations, which can be quite costly.
  325. */
  326. if (smp == smp_mode) {
  327. /* nothing */
  328. } else if (smp) {
  329. printk(KERN_INFO "SMP alternatives: switching to SMP code\n");
  330. clear_cpu_cap(&boot_cpu_data, X86_FEATURE_UP);
  331. clear_cpu_cap(&cpu_data(0), X86_FEATURE_UP);
  332. list_for_each_entry(mod, &smp_alt_modules, next)
  333. alternatives_smp_lock(mod->locks, mod->locks_end,
  334. mod->text, mod->text_end);
  335. } else {
  336. printk(KERN_INFO "SMP alternatives: switching to UP code\n");
  337. set_cpu_cap(&boot_cpu_data, X86_FEATURE_UP);
  338. set_cpu_cap(&cpu_data(0), X86_FEATURE_UP);
  339. list_for_each_entry(mod, &smp_alt_modules, next)
  340. alternatives_smp_unlock(mod->locks, mod->locks_end,
  341. mod->text, mod->text_end);
  342. }
  343. smp_mode = smp;
  344. mutex_unlock(&smp_alt);
  345. }
  346. /* Return 1 if the address range is reserved for smp-alternatives */
  347. int alternatives_text_reserved(void *start, void *end)
  348. {
  349. struct smp_alt_module *mod;
  350. u8 **ptr;
  351. u8 *text_start = start;
  352. u8 *text_end = end;
  353. list_for_each_entry(mod, &smp_alt_modules, next) {
  354. if (mod->text > text_end || mod->text_end < text_start)
  355. continue;
  356. for (ptr = mod->locks; ptr < mod->locks_end; ptr++)
  357. if (text_start <= *ptr && text_end >= *ptr)
  358. return 1;
  359. }
  360. return 0;
  361. }
  362. #endif
  363. #ifdef CONFIG_PARAVIRT
  364. void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
  365. struct paravirt_patch_site *end)
  366. {
  367. struct paravirt_patch_site *p;
  368. char insnbuf[MAX_PATCH_LEN];
  369. if (noreplace_paravirt)
  370. return;
  371. for (p = start; p < end; p++) {
  372. unsigned int used;
  373. BUG_ON(p->len > MAX_PATCH_LEN);
  374. /* prep the buffer with the original instructions */
  375. memcpy(insnbuf, p->instr, p->len);
  376. used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
  377. (unsigned long)p->instr, p->len);
  378. BUG_ON(used > p->len);
  379. /* Pad the rest with nops */
  380. add_nops(insnbuf + used, p->len - used);
  381. text_poke_early(p->instr, insnbuf, p->len);
  382. }
  383. }
  384. extern struct paravirt_patch_site __start_parainstructions[],
  385. __stop_parainstructions[];
  386. #endif /* CONFIG_PARAVIRT */
  387. void __init alternative_instructions(void)
  388. {
  389. /* The patching is not fully atomic, so try to avoid local interruptions
  390. that might execute the to be patched code.
  391. Other CPUs are not running. */
  392. stop_nmi();
  393. /*
  394. * Don't stop machine check exceptions while patching.
  395. * MCEs only happen when something got corrupted and in this
  396. * case we must do something about the corruption.
  397. * Ignoring it is worse than a unlikely patching race.
  398. * Also machine checks tend to be broadcast and if one CPU
  399. * goes into machine check the others follow quickly, so we don't
  400. * expect a machine check to cause undue problems during to code
  401. * patching.
  402. */
  403. apply_alternatives(__alt_instructions, __alt_instructions_end);
  404. /* switch to patch-once-at-boottime-only mode and free the
  405. * tables in case we know the number of CPUs will never ever
  406. * change */
  407. #ifdef CONFIG_HOTPLUG_CPU
  408. if (num_possible_cpus() < 2)
  409. smp_alt_once = 1;
  410. #endif
  411. #ifdef CONFIG_SMP
  412. if (smp_alt_once) {
  413. if (1 == num_possible_cpus()) {
  414. printk(KERN_INFO "SMP alternatives: switching to UP code\n");
  415. set_cpu_cap(&boot_cpu_data, X86_FEATURE_UP);
  416. set_cpu_cap(&cpu_data(0), X86_FEATURE_UP);
  417. alternatives_smp_unlock(__smp_locks, __smp_locks_end,
  418. _text, _etext);
  419. }
  420. } else {
  421. alternatives_smp_module_add(NULL, "core kernel",
  422. __smp_locks, __smp_locks_end,
  423. _text, _etext);
  424. /* Only switch to UP mode if we don't immediately boot others */
  425. if (num_present_cpus() == 1 || setup_max_cpus <= 1)
  426. alternatives_smp_switch(0);
  427. }
  428. #endif
  429. apply_paravirt(__parainstructions, __parainstructions_end);
  430. if (smp_alt_once)
  431. free_init_pages("SMP alternatives",
  432. (unsigned long)__smp_locks,
  433. (unsigned long)__smp_locks_end);
  434. restart_nmi();
  435. }
  436. /**
  437. * text_poke_early - Update instructions on a live kernel at boot time
  438. * @addr: address to modify
  439. * @opcode: source of the copy
  440. * @len: length to copy
  441. *
  442. * When you use this code to patch more than one byte of an instruction
  443. * you need to make sure that other CPUs cannot execute this code in parallel.
  444. * Also no thread must be currently preempted in the middle of these
  445. * instructions. And on the local CPU you need to be protected again NMI or MCE
  446. * handlers seeing an inconsistent instruction while you patch.
  447. */
  448. static void *__init_or_module text_poke_early(void *addr, const void *opcode,
  449. size_t len)
  450. {
  451. unsigned long flags;
  452. local_irq_save(flags);
  453. memcpy(addr, opcode, len);
  454. sync_core();
  455. local_irq_restore(flags);
  456. /* Could also do a CLFLUSH here to speed up CPU recovery; but
  457. that causes hangs on some VIA CPUs. */
  458. return addr;
  459. }
  460. /**
  461. * text_poke - Update instructions on a live kernel
  462. * @addr: address to modify
  463. * @opcode: source of the copy
  464. * @len: length to copy
  465. *
  466. * Only atomic text poke/set should be allowed when not doing early patching.
  467. * It means the size must be writable atomically and the address must be aligned
  468. * in a way that permits an atomic write. It also makes sure we fit on a single
  469. * page.
  470. *
  471. * Note: Must be called under text_mutex.
  472. */
  473. void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
  474. {
  475. unsigned long flags;
  476. char *vaddr;
  477. struct page *pages[2];
  478. int i;
  479. if (!core_kernel_text((unsigned long)addr)) {
  480. pages[0] = vmalloc_to_page(addr);
  481. pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
  482. } else {
  483. pages[0] = virt_to_page(addr);
  484. WARN_ON(!PageReserved(pages[0]));
  485. pages[1] = virt_to_page(addr + PAGE_SIZE);
  486. }
  487. BUG_ON(!pages[0]);
  488. local_irq_save(flags);
  489. set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
  490. if (pages[1])
  491. set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
  492. vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
  493. memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
  494. clear_fixmap(FIX_TEXT_POKE0);
  495. if (pages[1])
  496. clear_fixmap(FIX_TEXT_POKE1);
  497. local_flush_tlb();
  498. sync_core();
  499. /* Could also do a CLFLUSH here to speed up CPU recovery; but
  500. that causes hangs on some VIA CPUs. */
  501. for (i = 0; i < len; i++)
  502. BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
  503. local_irq_restore(flags);
  504. return addr;
  505. }
  506. /*
  507. * Cross-modifying kernel text with stop_machine().
  508. * This code originally comes from immediate value.
  509. */
  510. static atomic_t stop_machine_first;
  511. static int wrote_text;
  512. struct text_poke_params {
  513. void *addr;
  514. const void *opcode;
  515. size_t len;
  516. };
  517. static int __kprobes stop_machine_text_poke(void *data)
  518. {
  519. struct text_poke_params *tpp = data;
  520. if (atomic_dec_and_test(&stop_machine_first)) {
  521. text_poke(tpp->addr, tpp->opcode, tpp->len);
  522. smp_wmb(); /* Make sure other cpus see that this has run */
  523. wrote_text = 1;
  524. } else {
  525. while (!wrote_text)
  526. cpu_relax();
  527. smp_mb(); /* Load wrote_text before following execution */
  528. }
  529. flush_icache_range((unsigned long)tpp->addr,
  530. (unsigned long)tpp->addr + tpp->len);
  531. return 0;
  532. }
  533. /**
  534. * text_poke_smp - Update instructions on a live kernel on SMP
  535. * @addr: address to modify
  536. * @opcode: source of the copy
  537. * @len: length to copy
  538. *
  539. * Modify multi-byte instruction by using stop_machine() on SMP. This allows
  540. * user to poke/set multi-byte text on SMP. Only non-NMI/MCE code modifying
  541. * should be allowed, since stop_machine() does _not_ protect code against
  542. * NMI and MCE.
  543. *
  544. * Note: Must be called under get_online_cpus() and text_mutex.
  545. */
  546. void *__kprobes text_poke_smp(void *addr, const void *opcode, size_t len)
  547. {
  548. struct text_poke_params tpp;
  549. tpp.addr = addr;
  550. tpp.opcode = opcode;
  551. tpp.len = len;
  552. atomic_set(&stop_machine_first, 1);
  553. wrote_text = 0;
  554. stop_machine(stop_machine_text_poke, (void *)&tpp, NULL);
  555. return addr;
  556. }