smp.c 16 KB

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