smp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Xen SMP support
  3. *
  4. * This file implements the Xen versions of smp_ops. SMP under Xen is
  5. * very straightforward. Bringing a CPU up is simply a matter of
  6. * loading its initial context and setting it running.
  7. *
  8. * IPIs are handled through the Xen event mechanism.
  9. *
  10. * Because virtual CPUs can be scheduled onto any real CPU, there's no
  11. * useful topology information for the kernel to make use of. As a
  12. * result, all CPUs are treated as if they're single-core and
  13. * single-threaded.
  14. */
  15. #include <linux/sched.h>
  16. #include <linux/err.h>
  17. #include <linux/slab.h>
  18. #include <linux/smp.h>
  19. #include <linux/irq_work.h>
  20. #include <linux/tick.h>
  21. #include <asm/paravirt.h>
  22. #include <asm/desc.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/cpu.h>
  25. #include <xen/interface/xen.h>
  26. #include <xen/interface/vcpu.h>
  27. #include <asm/xen/interface.h>
  28. #include <asm/xen/hypercall.h>
  29. #include <xen/xen.h>
  30. #include <xen/page.h>
  31. #include <xen/events.h>
  32. #include <xen/hvc-console.h>
  33. #include "xen-ops.h"
  34. #include "mmu.h"
  35. cpumask_var_t xen_cpu_initialized_map;
  36. static DEFINE_PER_CPU(int, xen_resched_irq);
  37. static DEFINE_PER_CPU(int, xen_callfunc_irq);
  38. static DEFINE_PER_CPU(int, xen_callfuncsingle_irq);
  39. static DEFINE_PER_CPU(int, xen_irq_work);
  40. static DEFINE_PER_CPU(int, xen_debug_irq) = -1;
  41. static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id);
  42. static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id);
  43. static irqreturn_t xen_irq_work_interrupt(int irq, void *dev_id);
  44. /*
  45. * Reschedule call back.
  46. */
  47. static irqreturn_t xen_reschedule_interrupt(int irq, void *dev_id)
  48. {
  49. inc_irq_stat(irq_resched_count);
  50. scheduler_ipi();
  51. return IRQ_HANDLED;
  52. }
  53. static void __cpuinit cpu_bringup(void)
  54. {
  55. int cpu;
  56. cpu_init();
  57. touch_softlockup_watchdog();
  58. preempt_disable();
  59. xen_enable_sysenter();
  60. xen_enable_syscall();
  61. cpu = smp_processor_id();
  62. smp_store_cpu_info(cpu);
  63. cpu_data(cpu).x86_max_cores = 1;
  64. set_cpu_sibling_map(cpu);
  65. xen_setup_cpu_clockevents();
  66. notify_cpu_starting(cpu);
  67. set_cpu_online(cpu, true);
  68. this_cpu_write(cpu_state, CPU_ONLINE);
  69. wmb();
  70. /* We can take interrupts now: we're officially "up". */
  71. local_irq_enable();
  72. wmb(); /* make sure everything is out */
  73. }
  74. static void __cpuinit cpu_bringup_and_idle(void)
  75. {
  76. cpu_bringup();
  77. cpu_startup_entry(CPUHP_ONLINE);
  78. }
  79. static int xen_smp_intr_init(unsigned int cpu)
  80. {
  81. int rc;
  82. const char *resched_name, *callfunc_name, *debug_name;
  83. resched_name = kasprintf(GFP_KERNEL, "resched%d", cpu);
  84. rc = bind_ipi_to_irqhandler(XEN_RESCHEDULE_VECTOR,
  85. cpu,
  86. xen_reschedule_interrupt,
  87. IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING,
  88. resched_name,
  89. NULL);
  90. if (rc < 0)
  91. goto fail;
  92. per_cpu(xen_resched_irq, cpu) = rc;
  93. callfunc_name = kasprintf(GFP_KERNEL, "callfunc%d", cpu);
  94. rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_VECTOR,
  95. cpu,
  96. xen_call_function_interrupt,
  97. IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING,
  98. callfunc_name,
  99. NULL);
  100. if (rc < 0)
  101. goto fail;
  102. per_cpu(xen_callfunc_irq, cpu) = rc;
  103. debug_name = kasprintf(GFP_KERNEL, "debug%d", cpu);
  104. rc = bind_virq_to_irqhandler(VIRQ_DEBUG, cpu, xen_debug_interrupt,
  105. IRQF_DISABLED | IRQF_PERCPU | IRQF_NOBALANCING,
  106. debug_name, NULL);
  107. if (rc < 0)
  108. goto fail;
  109. per_cpu(xen_debug_irq, cpu) = rc;
  110. callfunc_name = kasprintf(GFP_KERNEL, "callfuncsingle%d", cpu);
  111. rc = bind_ipi_to_irqhandler(XEN_CALL_FUNCTION_SINGLE_VECTOR,
  112. cpu,
  113. xen_call_function_single_interrupt,
  114. IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING,
  115. callfunc_name,
  116. NULL);
  117. if (rc < 0)
  118. goto fail;
  119. per_cpu(xen_callfuncsingle_irq, cpu) = rc;
  120. /*
  121. * The IRQ worker on PVHVM goes through the native path and uses the
  122. * IPI mechanism.
  123. */
  124. if (xen_hvm_domain())
  125. return 0;
  126. callfunc_name = kasprintf(GFP_KERNEL, "irqwork%d", cpu);
  127. rc = bind_ipi_to_irqhandler(XEN_IRQ_WORK_VECTOR,
  128. cpu,
  129. xen_irq_work_interrupt,
  130. IRQF_DISABLED|IRQF_PERCPU|IRQF_NOBALANCING,
  131. callfunc_name,
  132. NULL);
  133. if (rc < 0)
  134. goto fail;
  135. per_cpu(xen_irq_work, cpu) = rc;
  136. return 0;
  137. fail:
  138. if (per_cpu(xen_resched_irq, cpu) >= 0)
  139. unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu), NULL);
  140. if (per_cpu(xen_callfunc_irq, cpu) >= 0)
  141. unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu), NULL);
  142. if (per_cpu(xen_debug_irq, cpu) >= 0)
  143. unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu), NULL);
  144. if (per_cpu(xen_callfuncsingle_irq, cpu) >= 0)
  145. unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu),
  146. NULL);
  147. if (xen_hvm_domain())
  148. return rc;
  149. if (per_cpu(xen_irq_work, cpu) >= 0)
  150. unbind_from_irqhandler(per_cpu(xen_irq_work, cpu), NULL);
  151. return rc;
  152. }
  153. static void __init xen_fill_possible_map(void)
  154. {
  155. int i, rc;
  156. if (xen_initial_domain())
  157. return;
  158. for (i = 0; i < nr_cpu_ids; i++) {
  159. rc = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
  160. if (rc >= 0) {
  161. num_processors++;
  162. set_cpu_possible(i, true);
  163. }
  164. }
  165. }
  166. static void __init xen_filter_cpu_maps(void)
  167. {
  168. int i, rc;
  169. unsigned int subtract = 0;
  170. if (!xen_initial_domain())
  171. return;
  172. num_processors = 0;
  173. disabled_cpus = 0;
  174. for (i = 0; i < nr_cpu_ids; i++) {
  175. rc = HYPERVISOR_vcpu_op(VCPUOP_is_up, i, NULL);
  176. if (rc >= 0) {
  177. num_processors++;
  178. set_cpu_possible(i, true);
  179. } else {
  180. set_cpu_possible(i, false);
  181. set_cpu_present(i, false);
  182. subtract++;
  183. }
  184. }
  185. #ifdef CONFIG_HOTPLUG_CPU
  186. /* This is akin to using 'nr_cpus' on the Linux command line.
  187. * Which is OK as when we use 'dom0_max_vcpus=X' we can only
  188. * have up to X, while nr_cpu_ids is greater than X. This
  189. * normally is not a problem, except when CPU hotplugging
  190. * is involved and then there might be more than X CPUs
  191. * in the guest - which will not work as there is no
  192. * hypercall to expand the max number of VCPUs an already
  193. * running guest has. So cap it up to X. */
  194. if (subtract)
  195. nr_cpu_ids = nr_cpu_ids - subtract;
  196. #endif
  197. }
  198. static void __init xen_smp_prepare_boot_cpu(void)
  199. {
  200. BUG_ON(smp_processor_id() != 0);
  201. native_smp_prepare_boot_cpu();
  202. /* We've switched to the "real" per-cpu gdt, so make sure the
  203. old memory can be recycled */
  204. make_lowmem_page_readwrite(xen_initial_gdt);
  205. xen_filter_cpu_maps();
  206. xen_setup_vcpu_info_placement();
  207. }
  208. static void __init xen_smp_prepare_cpus(unsigned int max_cpus)
  209. {
  210. unsigned cpu;
  211. unsigned int i;
  212. if (skip_ioapic_setup) {
  213. char *m = (max_cpus == 0) ?
  214. "The nosmp parameter is incompatible with Xen; " \
  215. "use Xen dom0_max_vcpus=1 parameter" :
  216. "The noapic parameter is incompatible with Xen";
  217. xen_raw_printk(m);
  218. panic(m);
  219. }
  220. xen_init_lock_cpu(0);
  221. smp_store_boot_cpu_info();
  222. cpu_data(0).x86_max_cores = 1;
  223. for_each_possible_cpu(i) {
  224. zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL);
  225. zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL);
  226. zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL);
  227. }
  228. set_cpu_sibling_map(0);
  229. if (xen_smp_intr_init(0))
  230. BUG();
  231. if (!alloc_cpumask_var(&xen_cpu_initialized_map, GFP_KERNEL))
  232. panic("could not allocate xen_cpu_initialized_map\n");
  233. cpumask_copy(xen_cpu_initialized_map, cpumask_of(0));
  234. /* Restrict the possible_map according to max_cpus. */
  235. while ((num_possible_cpus() > 1) && (num_possible_cpus() > max_cpus)) {
  236. for (cpu = nr_cpu_ids - 1; !cpu_possible(cpu); cpu--)
  237. continue;
  238. set_cpu_possible(cpu, false);
  239. }
  240. for_each_possible_cpu(cpu)
  241. set_cpu_present(cpu, true);
  242. }
  243. static int __cpuinit
  244. cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
  245. {
  246. struct vcpu_guest_context *ctxt;
  247. struct desc_struct *gdt;
  248. unsigned long gdt_mfn;
  249. if (cpumask_test_and_set_cpu(cpu, xen_cpu_initialized_map))
  250. return 0;
  251. ctxt = kzalloc(sizeof(*ctxt), GFP_KERNEL);
  252. if (ctxt == NULL)
  253. return -ENOMEM;
  254. gdt = get_cpu_gdt_table(cpu);
  255. ctxt->flags = VGCF_IN_KERNEL;
  256. ctxt->user_regs.ss = __KERNEL_DS;
  257. #ifdef CONFIG_X86_32
  258. ctxt->user_regs.fs = __KERNEL_PERCPU;
  259. ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
  260. #else
  261. ctxt->gs_base_kernel = per_cpu_offset(cpu);
  262. #endif
  263. ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
  264. memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
  265. {
  266. ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
  267. ctxt->user_regs.ds = __USER_DS;
  268. ctxt->user_regs.es = __USER_DS;
  269. xen_copy_trap_info(ctxt->trap_ctxt);
  270. ctxt->ldt_ents = 0;
  271. BUG_ON((unsigned long)gdt & ~PAGE_MASK);
  272. gdt_mfn = arbitrary_virt_to_mfn(gdt);
  273. make_lowmem_page_readonly(gdt);
  274. make_lowmem_page_readonly(mfn_to_virt(gdt_mfn));
  275. ctxt->gdt_frames[0] = gdt_mfn;
  276. ctxt->gdt_ents = GDT_ENTRIES;
  277. ctxt->kernel_ss = __KERNEL_DS;
  278. ctxt->kernel_sp = idle->thread.sp0;
  279. #ifdef CONFIG_X86_32
  280. ctxt->event_callback_cs = __KERNEL_CS;
  281. ctxt->failsafe_callback_cs = __KERNEL_CS;
  282. #endif
  283. ctxt->event_callback_eip =
  284. (unsigned long)xen_hypervisor_callback;
  285. ctxt->failsafe_callback_eip =
  286. (unsigned long)xen_failsafe_callback;
  287. }
  288. ctxt->user_regs.cs = __KERNEL_CS;
  289. ctxt->user_regs.esp = idle->thread.sp0 - sizeof(struct pt_regs);
  290. per_cpu(xen_cr3, cpu) = __pa(swapper_pg_dir);
  291. ctxt->ctrlreg[3] = xen_pfn_to_cr3(virt_to_mfn(swapper_pg_dir));
  292. if (HYPERVISOR_vcpu_op(VCPUOP_initialise, cpu, ctxt))
  293. BUG();
  294. kfree(ctxt);
  295. return 0;
  296. }
  297. static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
  298. {
  299. int rc;
  300. per_cpu(current_task, cpu) = idle;
  301. #ifdef CONFIG_X86_32
  302. irq_ctx_init(cpu);
  303. #else
  304. clear_tsk_thread_flag(idle, TIF_FORK);
  305. per_cpu(kernel_stack, cpu) =
  306. (unsigned long)task_stack_page(idle) -
  307. KERNEL_STACK_OFFSET + THREAD_SIZE;
  308. #endif
  309. xen_setup_runstate_info(cpu);
  310. xen_setup_timer(cpu);
  311. xen_init_lock_cpu(cpu);
  312. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  313. /* make sure interrupts start blocked */
  314. per_cpu(xen_vcpu, cpu)->evtchn_upcall_mask = 1;
  315. rc = cpu_initialize_context(cpu, idle);
  316. if (rc)
  317. return rc;
  318. if (num_online_cpus() == 1)
  319. /* Just in case we booted with a single CPU. */
  320. alternatives_enable_smp();
  321. rc = xen_smp_intr_init(cpu);
  322. if (rc)
  323. return rc;
  324. rc = HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL);
  325. BUG_ON(rc);
  326. while(per_cpu(cpu_state, cpu) != CPU_ONLINE) {
  327. HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
  328. barrier();
  329. }
  330. return 0;
  331. }
  332. static void xen_smp_cpus_done(unsigned int max_cpus)
  333. {
  334. }
  335. #ifdef CONFIG_HOTPLUG_CPU
  336. static int xen_cpu_disable(void)
  337. {
  338. unsigned int cpu = smp_processor_id();
  339. if (cpu == 0)
  340. return -EBUSY;
  341. cpu_disable_common();
  342. load_cr3(swapper_pg_dir);
  343. return 0;
  344. }
  345. static void xen_cpu_die(unsigned int cpu)
  346. {
  347. while (xen_pv_domain() && HYPERVISOR_vcpu_op(VCPUOP_is_up, cpu, NULL)) {
  348. current->state = TASK_UNINTERRUPTIBLE;
  349. schedule_timeout(HZ/10);
  350. }
  351. unbind_from_irqhandler(per_cpu(xen_resched_irq, cpu), NULL);
  352. unbind_from_irqhandler(per_cpu(xen_callfunc_irq, cpu), NULL);
  353. unbind_from_irqhandler(per_cpu(xen_debug_irq, cpu), NULL);
  354. unbind_from_irqhandler(per_cpu(xen_callfuncsingle_irq, cpu), NULL);
  355. if (!xen_hvm_domain())
  356. unbind_from_irqhandler(per_cpu(xen_irq_work, cpu), NULL);
  357. xen_uninit_lock_cpu(cpu);
  358. xen_teardown_timer(cpu);
  359. }
  360. static void __cpuinit xen_play_dead(void) /* used only with HOTPLUG_CPU */
  361. {
  362. play_dead_common();
  363. HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
  364. cpu_bringup();
  365. /*
  366. * commit 4b0c0f294 (tick: Cleanup NOHZ per cpu data on cpu down)
  367. * clears certain data that the cpu_idle loop (which called us
  368. * and that we return from) expects. The only way to get that
  369. * data back is to call:
  370. */
  371. tick_nohz_idle_enter();
  372. }
  373. #else /* !CONFIG_HOTPLUG_CPU */
  374. static int xen_cpu_disable(void)
  375. {
  376. return -ENOSYS;
  377. }
  378. static void xen_cpu_die(unsigned int cpu)
  379. {
  380. BUG();
  381. }
  382. static void xen_play_dead(void)
  383. {
  384. BUG();
  385. }
  386. #endif
  387. static void stop_self(void *v)
  388. {
  389. int cpu = smp_processor_id();
  390. /* make sure we're not pinning something down */
  391. load_cr3(swapper_pg_dir);
  392. /* should set up a minimal gdt */
  393. set_cpu_online(cpu, false);
  394. HYPERVISOR_vcpu_op(VCPUOP_down, cpu, NULL);
  395. BUG();
  396. }
  397. static void xen_stop_other_cpus(int wait)
  398. {
  399. smp_call_function(stop_self, NULL, wait);
  400. }
  401. static void xen_smp_send_reschedule(int cpu)
  402. {
  403. xen_send_IPI_one(cpu, XEN_RESCHEDULE_VECTOR);
  404. }
  405. static void __xen_send_IPI_mask(const struct cpumask *mask,
  406. int vector)
  407. {
  408. unsigned cpu;
  409. for_each_cpu_and(cpu, mask, cpu_online_mask)
  410. xen_send_IPI_one(cpu, vector);
  411. }
  412. static void xen_smp_send_call_function_ipi(const struct cpumask *mask)
  413. {
  414. int cpu;
  415. __xen_send_IPI_mask(mask, XEN_CALL_FUNCTION_VECTOR);
  416. /* Make sure other vcpus get a chance to run if they need to. */
  417. for_each_cpu(cpu, mask) {
  418. if (xen_vcpu_stolen(cpu)) {
  419. HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
  420. break;
  421. }
  422. }
  423. }
  424. static void xen_smp_send_call_function_single_ipi(int cpu)
  425. {
  426. __xen_send_IPI_mask(cpumask_of(cpu),
  427. XEN_CALL_FUNCTION_SINGLE_VECTOR);
  428. }
  429. static inline int xen_map_vector(int vector)
  430. {
  431. int xen_vector;
  432. switch (vector) {
  433. case RESCHEDULE_VECTOR:
  434. xen_vector = XEN_RESCHEDULE_VECTOR;
  435. break;
  436. case CALL_FUNCTION_VECTOR:
  437. xen_vector = XEN_CALL_FUNCTION_VECTOR;
  438. break;
  439. case CALL_FUNCTION_SINGLE_VECTOR:
  440. xen_vector = XEN_CALL_FUNCTION_SINGLE_VECTOR;
  441. break;
  442. case IRQ_WORK_VECTOR:
  443. xen_vector = XEN_IRQ_WORK_VECTOR;
  444. break;
  445. default:
  446. xen_vector = -1;
  447. printk(KERN_ERR "xen: vector 0x%x is not implemented\n",
  448. vector);
  449. }
  450. return xen_vector;
  451. }
  452. void xen_send_IPI_mask(const struct cpumask *mask,
  453. int vector)
  454. {
  455. int xen_vector = xen_map_vector(vector);
  456. if (xen_vector >= 0)
  457. __xen_send_IPI_mask(mask, xen_vector);
  458. }
  459. void xen_send_IPI_all(int vector)
  460. {
  461. int xen_vector = xen_map_vector(vector);
  462. if (xen_vector >= 0)
  463. __xen_send_IPI_mask(cpu_online_mask, xen_vector);
  464. }
  465. void xen_send_IPI_self(int vector)
  466. {
  467. int xen_vector = xen_map_vector(vector);
  468. if (xen_vector >= 0)
  469. xen_send_IPI_one(smp_processor_id(), xen_vector);
  470. }
  471. void xen_send_IPI_mask_allbutself(const struct cpumask *mask,
  472. int vector)
  473. {
  474. unsigned cpu;
  475. unsigned int this_cpu = smp_processor_id();
  476. int xen_vector = xen_map_vector(vector);
  477. if (!(num_online_cpus() > 1) || (xen_vector < 0))
  478. return;
  479. for_each_cpu_and(cpu, mask, cpu_online_mask) {
  480. if (this_cpu == cpu)
  481. continue;
  482. xen_send_IPI_one(cpu, xen_vector);
  483. }
  484. }
  485. void xen_send_IPI_allbutself(int vector)
  486. {
  487. xen_send_IPI_mask_allbutself(cpu_online_mask, vector);
  488. }
  489. static irqreturn_t xen_call_function_interrupt(int irq, void *dev_id)
  490. {
  491. irq_enter();
  492. generic_smp_call_function_interrupt();
  493. inc_irq_stat(irq_call_count);
  494. irq_exit();
  495. return IRQ_HANDLED;
  496. }
  497. static irqreturn_t xen_call_function_single_interrupt(int irq, void *dev_id)
  498. {
  499. irq_enter();
  500. generic_smp_call_function_single_interrupt();
  501. inc_irq_stat(irq_call_count);
  502. irq_exit();
  503. return IRQ_HANDLED;
  504. }
  505. static irqreturn_t xen_irq_work_interrupt(int irq, void *dev_id)
  506. {
  507. irq_enter();
  508. irq_work_run();
  509. inc_irq_stat(apic_irq_work_irqs);
  510. irq_exit();
  511. return IRQ_HANDLED;
  512. }
  513. static const struct smp_ops xen_smp_ops __initconst = {
  514. .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu,
  515. .smp_prepare_cpus = xen_smp_prepare_cpus,
  516. .smp_cpus_done = xen_smp_cpus_done,
  517. .cpu_up = xen_cpu_up,
  518. .cpu_die = xen_cpu_die,
  519. .cpu_disable = xen_cpu_disable,
  520. .play_dead = xen_play_dead,
  521. .stop_other_cpus = xen_stop_other_cpus,
  522. .smp_send_reschedule = xen_smp_send_reschedule,
  523. .send_call_func_ipi = xen_smp_send_call_function_ipi,
  524. .send_call_func_single_ipi = xen_smp_send_call_function_single_ipi,
  525. };
  526. void __init xen_smp_init(void)
  527. {
  528. smp_ops = xen_smp_ops;
  529. xen_fill_possible_map();
  530. xen_init_spinlocks();
  531. }
  532. static void __init xen_hvm_smp_prepare_cpus(unsigned int max_cpus)
  533. {
  534. native_smp_prepare_cpus(max_cpus);
  535. WARN_ON(xen_smp_intr_init(0));
  536. xen_init_lock_cpu(0);
  537. }
  538. static int __cpuinit xen_hvm_cpu_up(unsigned int cpu, struct task_struct *tidle)
  539. {
  540. int rc;
  541. rc = native_cpu_up(cpu, tidle);
  542. WARN_ON (xen_smp_intr_init(cpu));
  543. return rc;
  544. }
  545. static void xen_hvm_cpu_die(unsigned int cpu)
  546. {
  547. xen_cpu_die(cpu);
  548. native_cpu_die(cpu);
  549. }
  550. void __init xen_hvm_smp_init(void)
  551. {
  552. if (!xen_have_vector_callback)
  553. return;
  554. smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
  555. smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
  556. smp_ops.cpu_up = xen_hvm_cpu_up;
  557. smp_ops.cpu_die = xen_hvm_cpu_die;
  558. smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
  559. smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
  560. }