enlighten.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350
  1. /*
  2. * Core of Xen paravirt_ops implementation.
  3. *
  4. * This file contains the xen_paravirt_ops structure itself, and the
  5. * implementations for:
  6. * - privileged instructions
  7. * - interrupt flags
  8. * - segment operations
  9. * - booting and setup
  10. *
  11. * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/smp.h>
  16. #include <linux/preempt.h>
  17. #include <linux/hardirq.h>
  18. #include <linux/percpu.h>
  19. #include <linux/delay.h>
  20. #include <linux/start_kernel.h>
  21. #include <linux/sched.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/module.h>
  24. #include <linux/mm.h>
  25. #include <linux/page-flags.h>
  26. #include <linux/highmem.h>
  27. #include <linux/console.h>
  28. #include <xen/interface/xen.h>
  29. #include <xen/interface/physdev.h>
  30. #include <xen/interface/vcpu.h>
  31. #include <xen/interface/sched.h>
  32. #include <xen/features.h>
  33. #include <xen/page.h>
  34. #include <asm/paravirt.h>
  35. #include <asm/page.h>
  36. #include <asm/xen/hypercall.h>
  37. #include <asm/xen/hypervisor.h>
  38. #include <asm/fixmap.h>
  39. #include <asm/processor.h>
  40. #include <asm/setup.h>
  41. #include <asm/desc.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/tlbflush.h>
  44. #include <asm/reboot.h>
  45. #include "xen-ops.h"
  46. #include "mmu.h"
  47. #include "multicalls.h"
  48. EXPORT_SYMBOL_GPL(hypercall_page);
  49. DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
  50. DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
  51. /*
  52. * Note about cr3 (pagetable base) values:
  53. *
  54. * xen_cr3 contains the current logical cr3 value; it contains the
  55. * last set cr3. This may not be the current effective cr3, because
  56. * its update may be being lazily deferred. However, a vcpu looking
  57. * at its own cr3 can use this value knowing that it everything will
  58. * be self-consistent.
  59. *
  60. * xen_current_cr3 contains the actual vcpu cr3; it is set once the
  61. * hypercall to set the vcpu cr3 is complete (so it may be a little
  62. * out of date, but it will never be set early). If one vcpu is
  63. * looking at another vcpu's cr3 value, it should use this variable.
  64. */
  65. DEFINE_PER_CPU(unsigned long, xen_cr3); /* cr3 stored as physaddr */
  66. DEFINE_PER_CPU(unsigned long, xen_current_cr3); /* actual vcpu cr3 */
  67. struct start_info *xen_start_info;
  68. EXPORT_SYMBOL_GPL(xen_start_info);
  69. struct shared_info xen_dummy_shared_info;
  70. /*
  71. * Point at some empty memory to start with. We map the real shared_info
  72. * page as soon as fixmap is up and running.
  73. */
  74. struct shared_info *HYPERVISOR_shared_info = (void *)&xen_dummy_shared_info;
  75. /*
  76. * Flag to determine whether vcpu info placement is available on all
  77. * VCPUs. We assume it is to start with, and then set it to zero on
  78. * the first failure. This is because it can succeed on some VCPUs
  79. * and not others, since it can involve hypervisor memory allocation,
  80. * or because the guest failed to guarantee all the appropriate
  81. * constraints on all VCPUs (ie buffer can't cross a page boundary).
  82. *
  83. * Note that any particular CPU may be using a placed vcpu structure,
  84. * but we can only optimise if the all are.
  85. *
  86. * 0: not available, 1: available
  87. */
  88. static int have_vcpu_info_placement = 1;
  89. static void xen_vcpu_setup(int cpu)
  90. {
  91. struct vcpu_register_vcpu_info info;
  92. int err;
  93. struct vcpu_info *vcpup;
  94. BUG_ON(HYPERVISOR_shared_info == &xen_dummy_shared_info);
  95. per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
  96. if (!have_vcpu_info_placement)
  97. return; /* already tested, not available */
  98. vcpup = &per_cpu(xen_vcpu_info, cpu);
  99. info.mfn = virt_to_mfn(vcpup);
  100. info.offset = offset_in_page(vcpup);
  101. printk(KERN_DEBUG "trying to map vcpu_info %d at %p, mfn %llx, offset %d\n",
  102. cpu, vcpup, info.mfn, info.offset);
  103. /* Check to see if the hypervisor will put the vcpu_info
  104. structure where we want it, which allows direct access via
  105. a percpu-variable. */
  106. err = HYPERVISOR_vcpu_op(VCPUOP_register_vcpu_info, cpu, &info);
  107. if (err) {
  108. printk(KERN_DEBUG "register_vcpu_info failed: err=%d\n", err);
  109. have_vcpu_info_placement = 0;
  110. } else {
  111. /* This cpu is using the registered vcpu info, even if
  112. later ones fail to. */
  113. per_cpu(xen_vcpu, cpu) = vcpup;
  114. printk(KERN_DEBUG "cpu %d using vcpu_info at %p\n",
  115. cpu, vcpup);
  116. }
  117. }
  118. /*
  119. * On restore, set the vcpu placement up again.
  120. * If it fails, then we're in a bad state, since
  121. * we can't back out from using it...
  122. */
  123. void xen_vcpu_restore(void)
  124. {
  125. if (have_vcpu_info_placement) {
  126. int cpu;
  127. for_each_online_cpu(cpu) {
  128. bool other_cpu = (cpu != smp_processor_id());
  129. if (other_cpu &&
  130. HYPERVISOR_vcpu_op(VCPUOP_down, cpu, NULL))
  131. BUG();
  132. xen_vcpu_setup(cpu);
  133. if (other_cpu &&
  134. HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL))
  135. BUG();
  136. }
  137. BUG_ON(!have_vcpu_info_placement);
  138. }
  139. }
  140. static void __init xen_banner(void)
  141. {
  142. printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
  143. pv_info.name);
  144. printk(KERN_INFO "Hypervisor signature: %s%s\n",
  145. xen_start_info->magic,
  146. xen_feature(XENFEAT_mmu_pt_update_preserve_ad) ? " (preserve-AD)" : "");
  147. }
  148. static void xen_cpuid(unsigned int *ax, unsigned int *bx,
  149. unsigned int *cx, unsigned int *dx)
  150. {
  151. unsigned maskedx = ~0;
  152. /*
  153. * Mask out inconvenient features, to try and disable as many
  154. * unsupported kernel subsystems as possible.
  155. */
  156. if (*ax == 1)
  157. maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
  158. (1 << X86_FEATURE_ACPI) | /* disable ACPI */
  159. (1 << X86_FEATURE_MCE) | /* disable MCE */
  160. (1 << X86_FEATURE_MCA) | /* disable MCA */
  161. (1 << X86_FEATURE_ACC)); /* thermal monitoring */
  162. asm(XEN_EMULATE_PREFIX "cpuid"
  163. : "=a" (*ax),
  164. "=b" (*bx),
  165. "=c" (*cx),
  166. "=d" (*dx)
  167. : "0" (*ax), "2" (*cx));
  168. *dx &= maskedx;
  169. }
  170. static void xen_set_debugreg(int reg, unsigned long val)
  171. {
  172. HYPERVISOR_set_debugreg(reg, val);
  173. }
  174. static unsigned long xen_get_debugreg(int reg)
  175. {
  176. return HYPERVISOR_get_debugreg(reg);
  177. }
  178. static unsigned long xen_save_fl(void)
  179. {
  180. struct vcpu_info *vcpu;
  181. unsigned long flags;
  182. vcpu = x86_read_percpu(xen_vcpu);
  183. /* flag has opposite sense of mask */
  184. flags = !vcpu->evtchn_upcall_mask;
  185. /* convert to IF type flag
  186. -0 -> 0x00000000
  187. -1 -> 0xffffffff
  188. */
  189. return (-flags) & X86_EFLAGS_IF;
  190. }
  191. static void xen_restore_fl(unsigned long flags)
  192. {
  193. struct vcpu_info *vcpu;
  194. /* convert from IF type flag */
  195. flags = !(flags & X86_EFLAGS_IF);
  196. /* There's a one instruction preempt window here. We need to
  197. make sure we're don't switch CPUs between getting the vcpu
  198. pointer and updating the mask. */
  199. preempt_disable();
  200. vcpu = x86_read_percpu(xen_vcpu);
  201. vcpu->evtchn_upcall_mask = flags;
  202. preempt_enable_no_resched();
  203. /* Doesn't matter if we get preempted here, because any
  204. pending event will get dealt with anyway. */
  205. if (flags == 0) {
  206. preempt_check_resched();
  207. barrier(); /* unmask then check (avoid races) */
  208. if (unlikely(vcpu->evtchn_upcall_pending))
  209. force_evtchn_callback();
  210. }
  211. }
  212. static void xen_irq_disable(void)
  213. {
  214. /* There's a one instruction preempt window here. We need to
  215. make sure we're don't switch CPUs between getting the vcpu
  216. pointer and updating the mask. */
  217. preempt_disable();
  218. x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1;
  219. preempt_enable_no_resched();
  220. }
  221. static void xen_irq_enable(void)
  222. {
  223. struct vcpu_info *vcpu;
  224. /* We don't need to worry about being preempted here, since
  225. either a) interrupts are disabled, so no preemption, or b)
  226. the caller is confused and is trying to re-enable interrupts
  227. on an indeterminate processor. */
  228. vcpu = x86_read_percpu(xen_vcpu);
  229. vcpu->evtchn_upcall_mask = 0;
  230. /* Doesn't matter if we get preempted here, because any
  231. pending event will get dealt with anyway. */
  232. barrier(); /* unmask then check (avoid races) */
  233. if (unlikely(vcpu->evtchn_upcall_pending))
  234. force_evtchn_callback();
  235. }
  236. static void xen_safe_halt(void)
  237. {
  238. /* Blocking includes an implicit local_irq_enable(). */
  239. if (HYPERVISOR_sched_op(SCHEDOP_block, NULL) != 0)
  240. BUG();
  241. }
  242. static void xen_halt(void)
  243. {
  244. if (irqs_disabled())
  245. HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
  246. else
  247. xen_safe_halt();
  248. }
  249. static void xen_leave_lazy(void)
  250. {
  251. paravirt_leave_lazy(paravirt_get_lazy_mode());
  252. xen_mc_flush();
  253. }
  254. static unsigned long xen_store_tr(void)
  255. {
  256. return 0;
  257. }
  258. static void xen_set_ldt(const void *addr, unsigned entries)
  259. {
  260. struct mmuext_op *op;
  261. struct multicall_space mcs = xen_mc_entry(sizeof(*op));
  262. op = mcs.args;
  263. op->cmd = MMUEXT_SET_LDT;
  264. op->arg1.linear_addr = (unsigned long)addr;
  265. op->arg2.nr_ents = entries;
  266. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  267. xen_mc_issue(PARAVIRT_LAZY_CPU);
  268. }
  269. static void xen_load_gdt(const struct desc_ptr *dtr)
  270. {
  271. unsigned long *frames;
  272. unsigned long va = dtr->address;
  273. unsigned int size = dtr->size + 1;
  274. unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
  275. int f;
  276. struct multicall_space mcs;
  277. /* A GDT can be up to 64k in size, which corresponds to 8192
  278. 8-byte entries, or 16 4k pages.. */
  279. BUG_ON(size > 65536);
  280. BUG_ON(va & ~PAGE_MASK);
  281. mcs = xen_mc_entry(sizeof(*frames) * pages);
  282. frames = mcs.args;
  283. for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
  284. frames[f] = virt_to_mfn(va);
  285. make_lowmem_page_readonly((void *)va);
  286. }
  287. MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
  288. xen_mc_issue(PARAVIRT_LAZY_CPU);
  289. }
  290. static void load_TLS_descriptor(struct thread_struct *t,
  291. unsigned int cpu, unsigned int i)
  292. {
  293. struct desc_struct *gdt = get_cpu_gdt_table(cpu);
  294. xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
  295. struct multicall_space mc = __xen_mc_entry(0);
  296. MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
  297. }
  298. static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
  299. {
  300. xen_mc_batch();
  301. load_TLS_descriptor(t, cpu, 0);
  302. load_TLS_descriptor(t, cpu, 1);
  303. load_TLS_descriptor(t, cpu, 2);
  304. xen_mc_issue(PARAVIRT_LAZY_CPU);
  305. /*
  306. * XXX sleazy hack: If we're being called in a lazy-cpu zone,
  307. * it means we're in a context switch, and %gs has just been
  308. * saved. This means we can zero it out to prevent faults on
  309. * exit from the hypervisor if the next process has no %gs.
  310. * Either way, it has been saved, and the new value will get
  311. * loaded properly. This will go away as soon as Xen has been
  312. * modified to not save/restore %gs for normal hypercalls.
  313. */
  314. if (paravirt_get_lazy_mode() == PARAVIRT_LAZY_CPU)
  315. loadsegment(gs, 0);
  316. }
  317. static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
  318. const void *ptr)
  319. {
  320. unsigned long lp = (unsigned long)&dt[entrynum];
  321. xmaddr_t mach_lp = virt_to_machine(lp);
  322. u64 entry = *(u64 *)ptr;
  323. preempt_disable();
  324. xen_mc_flush();
  325. if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
  326. BUG();
  327. preempt_enable();
  328. }
  329. static int cvt_gate_to_trap(int vector, u32 low, u32 high,
  330. struct trap_info *info)
  331. {
  332. u8 type, dpl;
  333. type = (high >> 8) & 0x1f;
  334. dpl = (high >> 13) & 3;
  335. if (type != 0xf && type != 0xe)
  336. return 0;
  337. info->vector = vector;
  338. info->address = (high & 0xffff0000) | (low & 0x0000ffff);
  339. info->cs = low >> 16;
  340. info->flags = dpl;
  341. /* interrupt gates clear IF */
  342. if (type == 0xe)
  343. info->flags |= 4;
  344. return 1;
  345. }
  346. /* Locations of each CPU's IDT */
  347. static DEFINE_PER_CPU(struct desc_ptr, idt_desc);
  348. /* Set an IDT entry. If the entry is part of the current IDT, then
  349. also update Xen. */
  350. static void xen_write_idt_entry(gate_desc *dt, int entrynum, const gate_desc *g)
  351. {
  352. unsigned long p = (unsigned long)&dt[entrynum];
  353. unsigned long start, end;
  354. preempt_disable();
  355. start = __get_cpu_var(idt_desc).address;
  356. end = start + __get_cpu_var(idt_desc).size + 1;
  357. xen_mc_flush();
  358. native_write_idt_entry(dt, entrynum, g);
  359. if (p >= start && (p + 8) <= end) {
  360. struct trap_info info[2];
  361. u32 *desc = (u32 *)g;
  362. info[1].address = 0;
  363. if (cvt_gate_to_trap(entrynum, desc[0], desc[1], &info[0]))
  364. if (HYPERVISOR_set_trap_table(info))
  365. BUG();
  366. }
  367. preempt_enable();
  368. }
  369. static void xen_convert_trap_info(const struct desc_ptr *desc,
  370. struct trap_info *traps)
  371. {
  372. unsigned in, out, count;
  373. count = (desc->size+1) / 8;
  374. BUG_ON(count > 256);
  375. for (in = out = 0; in < count; in++) {
  376. const u32 *entry = (u32 *)(desc->address + in * 8);
  377. if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
  378. out++;
  379. }
  380. traps[out].address = 0;
  381. }
  382. void xen_copy_trap_info(struct trap_info *traps)
  383. {
  384. const struct desc_ptr *desc = &__get_cpu_var(idt_desc);
  385. xen_convert_trap_info(desc, traps);
  386. }
  387. /* Load a new IDT into Xen. In principle this can be per-CPU, so we
  388. hold a spinlock to protect the static traps[] array (static because
  389. it avoids allocation, and saves stack space). */
  390. static void xen_load_idt(const struct desc_ptr *desc)
  391. {
  392. static DEFINE_SPINLOCK(lock);
  393. static struct trap_info traps[257];
  394. spin_lock(&lock);
  395. __get_cpu_var(idt_desc) = *desc;
  396. xen_convert_trap_info(desc, traps);
  397. xen_mc_flush();
  398. if (HYPERVISOR_set_trap_table(traps))
  399. BUG();
  400. spin_unlock(&lock);
  401. }
  402. /* Write a GDT descriptor entry. Ignore LDT descriptors, since
  403. they're handled differently. */
  404. static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
  405. const void *desc, int type)
  406. {
  407. preempt_disable();
  408. switch (type) {
  409. case DESC_LDT:
  410. case DESC_TSS:
  411. /* ignore */
  412. break;
  413. default: {
  414. xmaddr_t maddr = virt_to_machine(&dt[entry]);
  415. xen_mc_flush();
  416. if (HYPERVISOR_update_descriptor(maddr.maddr, *(u64 *)desc))
  417. BUG();
  418. }
  419. }
  420. preempt_enable();
  421. }
  422. static void xen_load_sp0(struct tss_struct *tss,
  423. struct thread_struct *thread)
  424. {
  425. struct multicall_space mcs = xen_mc_entry(0);
  426. MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->sp0);
  427. xen_mc_issue(PARAVIRT_LAZY_CPU);
  428. }
  429. static void xen_set_iopl_mask(unsigned mask)
  430. {
  431. struct physdev_set_iopl set_iopl;
  432. /* Force the change at ring 0. */
  433. set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
  434. HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
  435. }
  436. static void xen_io_delay(void)
  437. {
  438. }
  439. #ifdef CONFIG_X86_LOCAL_APIC
  440. static u32 xen_apic_read(unsigned long reg)
  441. {
  442. return 0;
  443. }
  444. static void xen_apic_write(unsigned long reg, u32 val)
  445. {
  446. /* Warn to see if there's any stray references */
  447. WARN_ON(1);
  448. }
  449. #endif
  450. static void xen_flush_tlb(void)
  451. {
  452. struct mmuext_op *op;
  453. struct multicall_space mcs;
  454. preempt_disable();
  455. mcs = xen_mc_entry(sizeof(*op));
  456. op = mcs.args;
  457. op->cmd = MMUEXT_TLB_FLUSH_LOCAL;
  458. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  459. xen_mc_issue(PARAVIRT_LAZY_MMU);
  460. preempt_enable();
  461. }
  462. static void xen_flush_tlb_single(unsigned long addr)
  463. {
  464. struct mmuext_op *op;
  465. struct multicall_space mcs;
  466. preempt_disable();
  467. mcs = xen_mc_entry(sizeof(*op));
  468. op = mcs.args;
  469. op->cmd = MMUEXT_INVLPG_LOCAL;
  470. op->arg1.linear_addr = addr & PAGE_MASK;
  471. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  472. xen_mc_issue(PARAVIRT_LAZY_MMU);
  473. preempt_enable();
  474. }
  475. static void xen_flush_tlb_others(const cpumask_t *cpus, struct mm_struct *mm,
  476. unsigned long va)
  477. {
  478. struct {
  479. struct mmuext_op op;
  480. cpumask_t mask;
  481. } *args;
  482. cpumask_t cpumask = *cpus;
  483. struct multicall_space mcs;
  484. /*
  485. * A couple of (to be removed) sanity checks:
  486. *
  487. * - current CPU must not be in mask
  488. * - mask must exist :)
  489. */
  490. BUG_ON(cpus_empty(cpumask));
  491. BUG_ON(cpu_isset(smp_processor_id(), cpumask));
  492. BUG_ON(!mm);
  493. /* If a CPU which we ran on has gone down, OK. */
  494. cpus_and(cpumask, cpumask, cpu_online_map);
  495. if (cpus_empty(cpumask))
  496. return;
  497. mcs = xen_mc_entry(sizeof(*args));
  498. args = mcs.args;
  499. args->mask = cpumask;
  500. args->op.arg2.vcpumask = &args->mask;
  501. if (va == TLB_FLUSH_ALL) {
  502. args->op.cmd = MMUEXT_TLB_FLUSH_MULTI;
  503. } else {
  504. args->op.cmd = MMUEXT_INVLPG_MULTI;
  505. args->op.arg1.linear_addr = va;
  506. }
  507. MULTI_mmuext_op(mcs.mc, &args->op, 1, NULL, DOMID_SELF);
  508. xen_mc_issue(PARAVIRT_LAZY_MMU);
  509. }
  510. static void xen_clts(void)
  511. {
  512. struct multicall_space mcs;
  513. mcs = xen_mc_entry(0);
  514. MULTI_fpu_taskswitch(mcs.mc, 0);
  515. xen_mc_issue(PARAVIRT_LAZY_CPU);
  516. }
  517. static void xen_write_cr0(unsigned long cr0)
  518. {
  519. struct multicall_space mcs;
  520. /* Only pay attention to cr0.TS; everything else is
  521. ignored. */
  522. mcs = xen_mc_entry(0);
  523. MULTI_fpu_taskswitch(mcs.mc, (cr0 & X86_CR0_TS) != 0);
  524. xen_mc_issue(PARAVIRT_LAZY_CPU);
  525. }
  526. static void xen_write_cr2(unsigned long cr2)
  527. {
  528. x86_read_percpu(xen_vcpu)->arch.cr2 = cr2;
  529. }
  530. static unsigned long xen_read_cr2(void)
  531. {
  532. return x86_read_percpu(xen_vcpu)->arch.cr2;
  533. }
  534. static unsigned long xen_read_cr2_direct(void)
  535. {
  536. return x86_read_percpu(xen_vcpu_info.arch.cr2);
  537. }
  538. static void xen_write_cr4(unsigned long cr4)
  539. {
  540. cr4 &= ~X86_CR4_PGE;
  541. cr4 &= ~X86_CR4_PSE;
  542. native_write_cr4(cr4);
  543. }
  544. static unsigned long xen_read_cr3(void)
  545. {
  546. return x86_read_percpu(xen_cr3);
  547. }
  548. static void set_current_cr3(void *v)
  549. {
  550. x86_write_percpu(xen_current_cr3, (unsigned long)v);
  551. }
  552. static void xen_write_cr3(unsigned long cr3)
  553. {
  554. struct mmuext_op *op;
  555. struct multicall_space mcs;
  556. unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
  557. BUG_ON(preemptible());
  558. mcs = xen_mc_entry(sizeof(*op)); /* disables interrupts */
  559. /* Update while interrupts are disabled, so its atomic with
  560. respect to ipis */
  561. x86_write_percpu(xen_cr3, cr3);
  562. op = mcs.args;
  563. op->cmd = MMUEXT_NEW_BASEPTR;
  564. op->arg1.mfn = mfn;
  565. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  566. /* Update xen_update_cr3 once the batch has actually
  567. been submitted. */
  568. xen_mc_callback(set_current_cr3, (void *)cr3);
  569. xen_mc_issue(PARAVIRT_LAZY_CPU); /* interrupts restored */
  570. }
  571. /* Early in boot, while setting up the initial pagetable, assume
  572. everything is pinned. */
  573. static __init void xen_alloc_pte_init(struct mm_struct *mm, u32 pfn)
  574. {
  575. #ifdef CONFIG_FLATMEM
  576. BUG_ON(mem_map); /* should only be used early */
  577. #endif
  578. make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
  579. }
  580. /* Early release_pte assumes that all pts are pinned, since there's
  581. only init_mm and anything attached to that is pinned. */
  582. static void xen_release_pte_init(u32 pfn)
  583. {
  584. make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
  585. }
  586. static void pin_pagetable_pfn(unsigned cmd, unsigned long pfn)
  587. {
  588. struct mmuext_op op;
  589. op.cmd = cmd;
  590. op.arg1.mfn = pfn_to_mfn(pfn);
  591. if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
  592. BUG();
  593. }
  594. /* This needs to make sure the new pte page is pinned iff its being
  595. attached to a pinned pagetable. */
  596. static void xen_alloc_ptpage(struct mm_struct *mm, u32 pfn, unsigned level)
  597. {
  598. struct page *page = pfn_to_page(pfn);
  599. if (PagePinned(virt_to_page(mm->pgd))) {
  600. SetPagePinned(page);
  601. if (!PageHighMem(page)) {
  602. make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
  603. if (level == PT_PTE)
  604. pin_pagetable_pfn(MMUEXT_PIN_L1_TABLE, pfn);
  605. } else
  606. /* make sure there are no stray mappings of
  607. this page */
  608. kmap_flush_unused();
  609. }
  610. }
  611. static void xen_alloc_pte(struct mm_struct *mm, u32 pfn)
  612. {
  613. xen_alloc_ptpage(mm, pfn, PT_PTE);
  614. }
  615. static void xen_alloc_pmd(struct mm_struct *mm, u32 pfn)
  616. {
  617. xen_alloc_ptpage(mm, pfn, PT_PMD);
  618. }
  619. /* This should never happen until we're OK to use struct page */
  620. static void xen_release_ptpage(u32 pfn, unsigned level)
  621. {
  622. struct page *page = pfn_to_page(pfn);
  623. if (PagePinned(page)) {
  624. if (!PageHighMem(page)) {
  625. if (level == PT_PTE)
  626. pin_pagetable_pfn(MMUEXT_UNPIN_TABLE, pfn);
  627. make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
  628. }
  629. ClearPagePinned(page);
  630. }
  631. }
  632. static void xen_release_pte(u32 pfn)
  633. {
  634. xen_release_ptpage(pfn, PT_PTE);
  635. }
  636. static void xen_release_pmd(u32 pfn)
  637. {
  638. xen_release_ptpage(pfn, PT_PMD);
  639. }
  640. #ifdef CONFIG_HIGHPTE
  641. static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
  642. {
  643. pgprot_t prot = PAGE_KERNEL;
  644. if (PagePinned(page))
  645. prot = PAGE_KERNEL_RO;
  646. if (0 && PageHighMem(page))
  647. printk("mapping highpte %lx type %d prot %s\n",
  648. page_to_pfn(page), type,
  649. (unsigned long)pgprot_val(prot) & _PAGE_RW ? "WRITE" : "READ");
  650. return kmap_atomic_prot(page, type, prot);
  651. }
  652. #endif
  653. static __init pte_t mask_rw_pte(pte_t *ptep, pte_t pte)
  654. {
  655. /* If there's an existing pte, then don't allow _PAGE_RW to be set */
  656. if (pte_val_ma(*ptep) & _PAGE_PRESENT)
  657. pte = __pte_ma(((pte_val_ma(*ptep) & _PAGE_RW) | ~_PAGE_RW) &
  658. pte_val_ma(pte));
  659. return pte;
  660. }
  661. /* Init-time set_pte while constructing initial pagetables, which
  662. doesn't allow RO pagetable pages to be remapped RW */
  663. static __init void xen_set_pte_init(pte_t *ptep, pte_t pte)
  664. {
  665. pte = mask_rw_pte(ptep, pte);
  666. xen_set_pte(ptep, pte);
  667. }
  668. static __init void xen_pagetable_setup_start(pgd_t *base)
  669. {
  670. pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
  671. int i;
  672. /* special set_pte for pagetable initialization */
  673. pv_mmu_ops.set_pte = xen_set_pte_init;
  674. init_mm.pgd = base;
  675. /*
  676. * copy top-level of Xen-supplied pagetable into place. This
  677. * is a stand-in while we copy the pmd pages.
  678. */
  679. memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
  680. /*
  681. * For PAE, need to allocate new pmds, rather than
  682. * share Xen's, since Xen doesn't like pmd's being
  683. * shared between address spaces.
  684. */
  685. for (i = 0; i < PTRS_PER_PGD; i++) {
  686. if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
  687. pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  688. memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
  689. PAGE_SIZE);
  690. make_lowmem_page_readonly(pmd);
  691. set_pgd(&base[i], __pgd(1 + __pa(pmd)));
  692. } else
  693. pgd_clear(&base[i]);
  694. }
  695. /* make sure zero_page is mapped RO so we can use it in pagetables */
  696. make_lowmem_page_readonly(empty_zero_page);
  697. make_lowmem_page_readonly(base);
  698. /*
  699. * Switch to new pagetable. This is done before
  700. * pagetable_init has done anything so that the new pages
  701. * added to the table can be prepared properly for Xen.
  702. */
  703. xen_write_cr3(__pa(base));
  704. /* Unpin initial Xen pagetable */
  705. pin_pagetable_pfn(MMUEXT_UNPIN_TABLE,
  706. PFN_DOWN(__pa(xen_start_info->pt_base)));
  707. }
  708. void xen_setup_shared_info(void)
  709. {
  710. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  711. unsigned long addr = fix_to_virt(FIX_PARAVIRT_BOOTMAP);
  712. /*
  713. * Create a mapping for the shared info page.
  714. * Should be set_fixmap(), but shared_info is a machine
  715. * address with no corresponding pseudo-phys address.
  716. */
  717. set_pte_mfn(addr,
  718. PFN_DOWN(xen_start_info->shared_info),
  719. PAGE_KERNEL);
  720. HYPERVISOR_shared_info = (struct shared_info *)addr;
  721. } else
  722. HYPERVISOR_shared_info =
  723. (struct shared_info *)__va(xen_start_info->shared_info);
  724. #ifndef CONFIG_SMP
  725. /* In UP this is as good a place as any to set up shared info */
  726. xen_setup_vcpu_info_placement();
  727. #endif
  728. xen_setup_mfn_list_list();
  729. }
  730. static __init void xen_pagetable_setup_done(pgd_t *base)
  731. {
  732. /* This will work as long as patching hasn't happened yet
  733. (which it hasn't) */
  734. pv_mmu_ops.alloc_pte = xen_alloc_pte;
  735. pv_mmu_ops.alloc_pmd = xen_alloc_pmd;
  736. pv_mmu_ops.release_pte = xen_release_pte;
  737. pv_mmu_ops.release_pmd = xen_release_pmd;
  738. pv_mmu_ops.set_pte = xen_set_pte;
  739. xen_setup_shared_info();
  740. /* Actually pin the pagetable down, but we can't set PG_pinned
  741. yet because the page structures don't exist yet. */
  742. pin_pagetable_pfn(MMUEXT_PIN_L3_TABLE, PFN_DOWN(__pa(base)));
  743. }
  744. static __init void xen_post_allocator_init(void)
  745. {
  746. pv_mmu_ops.set_pmd = xen_set_pmd;
  747. pv_mmu_ops.set_pud = xen_set_pud;
  748. xen_mark_init_mm_pinned();
  749. }
  750. /* This is called once we have the cpu_possible_map */
  751. void xen_setup_vcpu_info_placement(void)
  752. {
  753. int cpu;
  754. for_each_possible_cpu(cpu)
  755. xen_vcpu_setup(cpu);
  756. /* xen_vcpu_setup managed to place the vcpu_info within the
  757. percpu area for all cpus, so make use of it */
  758. if (have_vcpu_info_placement) {
  759. printk(KERN_INFO "Xen: using vcpu_info placement\n");
  760. pv_irq_ops.save_fl = xen_save_fl_direct;
  761. pv_irq_ops.restore_fl = xen_restore_fl_direct;
  762. pv_irq_ops.irq_disable = xen_irq_disable_direct;
  763. pv_irq_ops.irq_enable = xen_irq_enable_direct;
  764. pv_mmu_ops.read_cr2 = xen_read_cr2_direct;
  765. }
  766. }
  767. static unsigned xen_patch(u8 type, u16 clobbers, void *insnbuf,
  768. unsigned long addr, unsigned len)
  769. {
  770. char *start, *end, *reloc;
  771. unsigned ret;
  772. start = end = reloc = NULL;
  773. #define SITE(op, x) \
  774. case PARAVIRT_PATCH(op.x): \
  775. if (have_vcpu_info_placement) { \
  776. start = (char *)xen_##x##_direct; \
  777. end = xen_##x##_direct_end; \
  778. reloc = xen_##x##_direct_reloc; \
  779. } \
  780. goto patch_site
  781. switch (type) {
  782. SITE(pv_irq_ops, irq_enable);
  783. SITE(pv_irq_ops, irq_disable);
  784. SITE(pv_irq_ops, save_fl);
  785. SITE(pv_irq_ops, restore_fl);
  786. #undef SITE
  787. patch_site:
  788. if (start == NULL || (end-start) > len)
  789. goto default_patch;
  790. ret = paravirt_patch_insns(insnbuf, len, start, end);
  791. /* Note: because reloc is assigned from something that
  792. appears to be an array, gcc assumes it's non-null,
  793. but doesn't know its relationship with start and
  794. end. */
  795. if (reloc > start && reloc < end) {
  796. int reloc_off = reloc - start;
  797. long *relocp = (long *)(insnbuf + reloc_off);
  798. long delta = start - (char *)addr;
  799. *relocp += delta;
  800. }
  801. break;
  802. default_patch:
  803. default:
  804. ret = paravirt_patch_default(type, clobbers, insnbuf,
  805. addr, len);
  806. break;
  807. }
  808. return ret;
  809. }
  810. static void xen_set_fixmap(unsigned idx, unsigned long phys, pgprot_t prot)
  811. {
  812. pte_t pte;
  813. phys >>= PAGE_SHIFT;
  814. switch (idx) {
  815. case FIX_BTMAP_END ... FIX_BTMAP_BEGIN:
  816. #ifdef CONFIG_X86_F00F_BUG
  817. case FIX_F00F_IDT:
  818. #endif
  819. case FIX_WP_TEST:
  820. case FIX_VDSO:
  821. #ifdef CONFIG_X86_LOCAL_APIC
  822. case FIX_APIC_BASE: /* maps dummy local APIC */
  823. #endif
  824. pte = pfn_pte(phys, prot);
  825. break;
  826. default:
  827. pte = mfn_pte(phys, prot);
  828. break;
  829. }
  830. __native_set_fixmap(idx, pte);
  831. }
  832. static const struct pv_info xen_info __initdata = {
  833. .paravirt_enabled = 1,
  834. .shared_kernel_pmd = 0,
  835. .name = "Xen",
  836. };
  837. static const struct pv_init_ops xen_init_ops __initdata = {
  838. .patch = xen_patch,
  839. .banner = xen_banner,
  840. .memory_setup = xen_memory_setup,
  841. .arch_setup = xen_arch_setup,
  842. .post_allocator_init = xen_post_allocator_init,
  843. };
  844. static const struct pv_time_ops xen_time_ops __initdata = {
  845. .time_init = xen_time_init,
  846. .set_wallclock = xen_set_wallclock,
  847. .get_wallclock = xen_get_wallclock,
  848. .get_cpu_khz = xen_cpu_khz,
  849. .sched_clock = xen_sched_clock,
  850. };
  851. static const struct pv_cpu_ops xen_cpu_ops __initdata = {
  852. .cpuid = xen_cpuid,
  853. .set_debugreg = xen_set_debugreg,
  854. .get_debugreg = xen_get_debugreg,
  855. .clts = xen_clts,
  856. .read_cr0 = native_read_cr0,
  857. .write_cr0 = xen_write_cr0,
  858. .read_cr4 = native_read_cr4,
  859. .read_cr4_safe = native_read_cr4_safe,
  860. .write_cr4 = xen_write_cr4,
  861. .wbinvd = native_wbinvd,
  862. .read_msr = native_read_msr_safe,
  863. .write_msr = native_write_msr_safe,
  864. .read_tsc = native_read_tsc,
  865. .read_pmc = native_read_pmc,
  866. .iret = xen_iret,
  867. .irq_enable_syscall_ret = xen_sysexit,
  868. .load_tr_desc = paravirt_nop,
  869. .set_ldt = xen_set_ldt,
  870. .load_gdt = xen_load_gdt,
  871. .load_idt = xen_load_idt,
  872. .load_tls = xen_load_tls,
  873. .store_gdt = native_store_gdt,
  874. .store_idt = native_store_idt,
  875. .store_tr = xen_store_tr,
  876. .write_ldt_entry = xen_write_ldt_entry,
  877. .write_gdt_entry = xen_write_gdt_entry,
  878. .write_idt_entry = xen_write_idt_entry,
  879. .load_sp0 = xen_load_sp0,
  880. .set_iopl_mask = xen_set_iopl_mask,
  881. .io_delay = xen_io_delay,
  882. .lazy_mode = {
  883. .enter = paravirt_enter_lazy_cpu,
  884. .leave = xen_leave_lazy,
  885. },
  886. };
  887. static const struct pv_irq_ops xen_irq_ops __initdata = {
  888. .init_IRQ = xen_init_IRQ,
  889. .save_fl = xen_save_fl,
  890. .restore_fl = xen_restore_fl,
  891. .irq_disable = xen_irq_disable,
  892. .irq_enable = xen_irq_enable,
  893. .safe_halt = xen_safe_halt,
  894. .halt = xen_halt,
  895. };
  896. static const struct pv_apic_ops xen_apic_ops __initdata = {
  897. #ifdef CONFIG_X86_LOCAL_APIC
  898. .apic_write = xen_apic_write,
  899. .apic_write_atomic = xen_apic_write,
  900. .apic_read = xen_apic_read,
  901. .setup_boot_clock = paravirt_nop,
  902. .setup_secondary_clock = paravirt_nop,
  903. .startup_ipi_hook = paravirt_nop,
  904. #endif
  905. };
  906. static const struct pv_mmu_ops xen_mmu_ops __initdata = {
  907. .pagetable_setup_start = xen_pagetable_setup_start,
  908. .pagetable_setup_done = xen_pagetable_setup_done,
  909. .read_cr2 = xen_read_cr2,
  910. .write_cr2 = xen_write_cr2,
  911. .read_cr3 = xen_read_cr3,
  912. .write_cr3 = xen_write_cr3,
  913. .flush_tlb_user = xen_flush_tlb,
  914. .flush_tlb_kernel = xen_flush_tlb,
  915. .flush_tlb_single = xen_flush_tlb_single,
  916. .flush_tlb_others = xen_flush_tlb_others,
  917. .pte_update = paravirt_nop,
  918. .pte_update_defer = paravirt_nop,
  919. .alloc_pte = xen_alloc_pte_init,
  920. .release_pte = xen_release_pte_init,
  921. .alloc_pmd = xen_alloc_pte_init,
  922. .alloc_pmd_clone = paravirt_nop,
  923. .release_pmd = xen_release_pte_init,
  924. #ifdef CONFIG_HIGHPTE
  925. .kmap_atomic_pte = xen_kmap_atomic_pte,
  926. #endif
  927. .set_pte = NULL, /* see xen_pagetable_setup_* */
  928. .set_pte_at = xen_set_pte_at,
  929. .set_pmd = xen_set_pmd_hyper,
  930. .ptep_modify_prot_start = __ptep_modify_prot_start,
  931. .ptep_modify_prot_commit = __ptep_modify_prot_commit,
  932. .pte_val = xen_pte_val,
  933. .pte_flags = native_pte_val,
  934. .pgd_val = xen_pgd_val,
  935. .make_pte = xen_make_pte,
  936. .make_pgd = xen_make_pgd,
  937. .set_pte_atomic = xen_set_pte_atomic,
  938. .set_pte_present = xen_set_pte_at,
  939. .set_pud = xen_set_pud_hyper,
  940. .pte_clear = xen_pte_clear,
  941. .pmd_clear = xen_pmd_clear,
  942. .make_pmd = xen_make_pmd,
  943. .pmd_val = xen_pmd_val,
  944. .activate_mm = xen_activate_mm,
  945. .dup_mmap = xen_dup_mmap,
  946. .exit_mmap = xen_exit_mmap,
  947. .lazy_mode = {
  948. .enter = paravirt_enter_lazy_mmu,
  949. .leave = xen_leave_lazy,
  950. },
  951. .set_fixmap = xen_set_fixmap,
  952. };
  953. #ifdef CONFIG_SMP
  954. static const struct smp_ops xen_smp_ops __initdata = {
  955. .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu,
  956. .smp_prepare_cpus = xen_smp_prepare_cpus,
  957. .cpu_up = xen_cpu_up,
  958. .smp_cpus_done = xen_smp_cpus_done,
  959. .smp_send_stop = xen_smp_send_stop,
  960. .smp_send_reschedule = xen_smp_send_reschedule,
  961. .smp_call_function_mask = xen_smp_call_function_mask,
  962. };
  963. #endif /* CONFIG_SMP */
  964. static void xen_reboot(int reason)
  965. {
  966. struct sched_shutdown r = { .reason = reason };
  967. #ifdef CONFIG_SMP
  968. smp_send_stop();
  969. #endif
  970. if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
  971. BUG();
  972. }
  973. static void xen_restart(char *msg)
  974. {
  975. xen_reboot(SHUTDOWN_reboot);
  976. }
  977. static void xen_emergency_restart(void)
  978. {
  979. xen_reboot(SHUTDOWN_reboot);
  980. }
  981. static void xen_machine_halt(void)
  982. {
  983. xen_reboot(SHUTDOWN_poweroff);
  984. }
  985. static void xen_crash_shutdown(struct pt_regs *regs)
  986. {
  987. xen_reboot(SHUTDOWN_crash);
  988. }
  989. static const struct machine_ops __initdata xen_machine_ops = {
  990. .restart = xen_restart,
  991. .halt = xen_machine_halt,
  992. .power_off = xen_machine_halt,
  993. .shutdown = xen_machine_halt,
  994. .crash_shutdown = xen_crash_shutdown,
  995. .emergency_restart = xen_emergency_restart,
  996. };
  997. static void __init xen_reserve_top(void)
  998. {
  999. unsigned long top = HYPERVISOR_VIRT_START;
  1000. struct xen_platform_parameters pp;
  1001. if (HYPERVISOR_xen_version(XENVER_platform_parameters, &pp) == 0)
  1002. top = pp.virt_start;
  1003. reserve_top_address(-top + 2 * PAGE_SIZE);
  1004. }
  1005. /* First C function to be called on Xen boot */
  1006. asmlinkage void __init xen_start_kernel(void)
  1007. {
  1008. pgd_t *pgd;
  1009. if (!xen_start_info)
  1010. return;
  1011. BUG_ON(memcmp(xen_start_info->magic, "xen-3", 5) != 0);
  1012. xen_setup_features();
  1013. /* Install Xen paravirt ops */
  1014. pv_info = xen_info;
  1015. pv_init_ops = xen_init_ops;
  1016. pv_time_ops = xen_time_ops;
  1017. pv_cpu_ops = xen_cpu_ops;
  1018. pv_irq_ops = xen_irq_ops;
  1019. pv_apic_ops = xen_apic_ops;
  1020. pv_mmu_ops = xen_mmu_ops;
  1021. if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
  1022. pv_mmu_ops.ptep_modify_prot_start = xen_ptep_modify_prot_start;
  1023. pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
  1024. }
  1025. machine_ops = xen_machine_ops;
  1026. #ifdef CONFIG_SMP
  1027. smp_ops = xen_smp_ops;
  1028. #endif
  1029. /* Get mfn list */
  1030. if (!xen_feature(XENFEAT_auto_translated_physmap))
  1031. xen_build_dynamic_phys_to_machine();
  1032. pgd = (pgd_t *)xen_start_info->pt_base;
  1033. init_pg_tables_start = __pa(pgd);
  1034. init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
  1035. init_mm.pgd = pgd; /* use the Xen pagetables to start */
  1036. /* keep using Xen gdt for now; no urgent need to change it */
  1037. x86_write_percpu(xen_cr3, __pa(pgd));
  1038. x86_write_percpu(xen_current_cr3, __pa(pgd));
  1039. /* Don't do the full vcpu_info placement stuff until we have a
  1040. possible map and a non-dummy shared_info. */
  1041. per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];
  1042. pv_info.kernel_rpl = 1;
  1043. if (xen_feature(XENFEAT_supervisor_mode_kernel))
  1044. pv_info.kernel_rpl = 0;
  1045. /* Prevent unwanted bits from being set in PTEs. */
  1046. __supported_pte_mask &= ~_PAGE_GLOBAL;
  1047. if (!is_initial_xendomain())
  1048. __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
  1049. /* set the limit of our address space */
  1050. xen_reserve_top();
  1051. /* set up basic CPUID stuff */
  1052. cpu_detect(&new_cpu_data);
  1053. new_cpu_data.hard_math = 1;
  1054. new_cpu_data.x86_capability[0] = cpuid_edx(1);
  1055. /* Poke various useful things into boot_params */
  1056. boot_params.hdr.type_of_loader = (9 << 4) | 0;
  1057. boot_params.hdr.ramdisk_image = xen_start_info->mod_start
  1058. ? __pa(xen_start_info->mod_start) : 0;
  1059. boot_params.hdr.ramdisk_size = xen_start_info->mod_len;
  1060. if (!is_initial_xendomain()) {
  1061. add_preferred_console("xenboot", 0, NULL);
  1062. add_preferred_console("tty", 0, NULL);
  1063. add_preferred_console("hvc", 0, NULL);
  1064. }
  1065. /* Start the world */
  1066. i386_start_kernel();
  1067. }