enlighten.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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/percpu.h>
  18. #include <linux/delay.h>
  19. #include <linux/start_kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/bootmem.h>
  22. #include <linux/module.h>
  23. #include <xen/interface/xen.h>
  24. #include <xen/interface/physdev.h>
  25. #include <xen/interface/vcpu.h>
  26. #include <xen/features.h>
  27. #include <xen/page.h>
  28. #include <asm/paravirt.h>
  29. #include <asm/page.h>
  30. #include <asm/xen/hypercall.h>
  31. #include <asm/xen/hypervisor.h>
  32. #include <asm/fixmap.h>
  33. #include <asm/processor.h>
  34. #include <asm/setup.h>
  35. #include <asm/desc.h>
  36. #include <asm/pgtable.h>
  37. #include "xen-ops.h"
  38. #include "multicalls.h"
  39. EXPORT_SYMBOL_GPL(hypercall_page);
  40. DEFINE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);
  41. DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
  42. DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
  43. DEFINE_PER_CPU(unsigned long, xen_cr3);
  44. struct start_info *xen_start_info;
  45. EXPORT_SYMBOL_GPL(xen_start_info);
  46. static void xen_vcpu_setup(int cpu)
  47. {
  48. per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
  49. }
  50. static void __init xen_banner(void)
  51. {
  52. printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
  53. paravirt_ops.name);
  54. printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
  55. }
  56. static void xen_cpuid(unsigned int *eax, unsigned int *ebx,
  57. unsigned int *ecx, unsigned int *edx)
  58. {
  59. unsigned maskedx = ~0;
  60. /*
  61. * Mask out inconvenient features, to try and disable as many
  62. * unsupported kernel subsystems as possible.
  63. */
  64. if (*eax == 1)
  65. maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
  66. (1 << X86_FEATURE_ACPI) | /* disable ACPI */
  67. (1 << X86_FEATURE_ACC)); /* thermal monitoring */
  68. asm(XEN_EMULATE_PREFIX "cpuid"
  69. : "=a" (*eax),
  70. "=b" (*ebx),
  71. "=c" (*ecx),
  72. "=d" (*edx)
  73. : "0" (*eax), "2" (*ecx));
  74. *edx &= maskedx;
  75. }
  76. static void xen_set_debugreg(int reg, unsigned long val)
  77. {
  78. HYPERVISOR_set_debugreg(reg, val);
  79. }
  80. static unsigned long xen_get_debugreg(int reg)
  81. {
  82. return HYPERVISOR_get_debugreg(reg);
  83. }
  84. static unsigned long xen_save_fl(void)
  85. {
  86. struct vcpu_info *vcpu;
  87. unsigned long flags;
  88. preempt_disable();
  89. vcpu = x86_read_percpu(xen_vcpu);
  90. /* flag has opposite sense of mask */
  91. flags = !vcpu->evtchn_upcall_mask;
  92. preempt_enable();
  93. /* convert to IF type flag
  94. -0 -> 0x00000000
  95. -1 -> 0xffffffff
  96. */
  97. return (-flags) & X86_EFLAGS_IF;
  98. }
  99. static void xen_restore_fl(unsigned long flags)
  100. {
  101. struct vcpu_info *vcpu;
  102. preempt_disable();
  103. /* convert from IF type flag */
  104. flags = !(flags & X86_EFLAGS_IF);
  105. vcpu = x86_read_percpu(xen_vcpu);
  106. vcpu->evtchn_upcall_mask = flags;
  107. if (flags == 0) {
  108. /* Unmask then check (avoid races). We're only protecting
  109. against updates by this CPU, so there's no need for
  110. anything stronger. */
  111. barrier();
  112. if (unlikely(vcpu->evtchn_upcall_pending))
  113. force_evtchn_callback();
  114. preempt_enable();
  115. } else
  116. preempt_enable_no_resched();
  117. }
  118. static void xen_irq_disable(void)
  119. {
  120. struct vcpu_info *vcpu;
  121. preempt_disable();
  122. vcpu = x86_read_percpu(xen_vcpu);
  123. vcpu->evtchn_upcall_mask = 1;
  124. preempt_enable_no_resched();
  125. }
  126. static void xen_irq_enable(void)
  127. {
  128. struct vcpu_info *vcpu;
  129. preempt_disable();
  130. vcpu = x86_read_percpu(xen_vcpu);
  131. vcpu->evtchn_upcall_mask = 0;
  132. /* Unmask then check (avoid races). We're only protecting
  133. against updates by this CPU, so there's no need for
  134. anything stronger. */
  135. barrier();
  136. if (unlikely(vcpu->evtchn_upcall_pending))
  137. force_evtchn_callback();
  138. preempt_enable();
  139. }
  140. static void xen_safe_halt(void)
  141. {
  142. /* Blocking includes an implicit local_irq_enable(). */
  143. if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
  144. BUG();
  145. }
  146. static void xen_halt(void)
  147. {
  148. if (irqs_disabled())
  149. HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
  150. else
  151. xen_safe_halt();
  152. }
  153. static void xen_set_lazy_mode(enum paravirt_lazy_mode mode)
  154. {
  155. switch (mode) {
  156. case PARAVIRT_LAZY_NONE:
  157. BUG_ON(x86_read_percpu(xen_lazy_mode) == PARAVIRT_LAZY_NONE);
  158. break;
  159. case PARAVIRT_LAZY_MMU:
  160. case PARAVIRT_LAZY_CPU:
  161. BUG_ON(x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE);
  162. break;
  163. case PARAVIRT_LAZY_FLUSH:
  164. /* flush if necessary, but don't change state */
  165. if (x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE)
  166. xen_mc_flush();
  167. return;
  168. }
  169. xen_mc_flush();
  170. x86_write_percpu(xen_lazy_mode, mode);
  171. }
  172. static unsigned long xen_store_tr(void)
  173. {
  174. return 0;
  175. }
  176. static void xen_set_ldt(const void *addr, unsigned entries)
  177. {
  178. unsigned long linear_addr = (unsigned long)addr;
  179. struct mmuext_op *op;
  180. struct multicall_space mcs = xen_mc_entry(sizeof(*op));
  181. op = mcs.args;
  182. op->cmd = MMUEXT_SET_LDT;
  183. if (linear_addr) {
  184. /* ldt my be vmalloced, use arbitrary_virt_to_machine */
  185. xmaddr_t maddr;
  186. maddr = arbitrary_virt_to_machine((unsigned long)addr);
  187. linear_addr = (unsigned long)maddr.maddr;
  188. }
  189. op->arg1.linear_addr = linear_addr;
  190. op->arg2.nr_ents = entries;
  191. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  192. xen_mc_issue(PARAVIRT_LAZY_CPU);
  193. }
  194. static void xen_load_gdt(const struct Xgt_desc_struct *dtr)
  195. {
  196. unsigned long *frames;
  197. unsigned long va = dtr->address;
  198. unsigned int size = dtr->size + 1;
  199. unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
  200. int f;
  201. struct multicall_space mcs;
  202. /* A GDT can be up to 64k in size, which corresponds to 8192
  203. 8-byte entries, or 16 4k pages.. */
  204. BUG_ON(size > 65536);
  205. BUG_ON(va & ~PAGE_MASK);
  206. mcs = xen_mc_entry(sizeof(*frames) * pages);
  207. frames = mcs.args;
  208. for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
  209. frames[f] = virt_to_mfn(va);
  210. make_lowmem_page_readonly((void *)va);
  211. }
  212. MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
  213. xen_mc_issue(PARAVIRT_LAZY_CPU);
  214. }
  215. static void load_TLS_descriptor(struct thread_struct *t,
  216. unsigned int cpu, unsigned int i)
  217. {
  218. struct desc_struct *gdt = get_cpu_gdt_table(cpu);
  219. xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
  220. struct multicall_space mc = __xen_mc_entry(0);
  221. MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
  222. }
  223. static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
  224. {
  225. xen_mc_batch();
  226. load_TLS_descriptor(t, cpu, 0);
  227. load_TLS_descriptor(t, cpu, 1);
  228. load_TLS_descriptor(t, cpu, 2);
  229. xen_mc_issue(PARAVIRT_LAZY_CPU);
  230. }
  231. static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
  232. u32 low, u32 high)
  233. {
  234. unsigned long lp = (unsigned long)&dt[entrynum];
  235. xmaddr_t mach_lp = virt_to_machine(lp);
  236. u64 entry = (u64)high << 32 | low;
  237. xen_mc_flush();
  238. if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
  239. BUG();
  240. }
  241. static int cvt_gate_to_trap(int vector, u32 low, u32 high,
  242. struct trap_info *info)
  243. {
  244. u8 type, dpl;
  245. type = (high >> 8) & 0x1f;
  246. dpl = (high >> 13) & 3;
  247. if (type != 0xf && type != 0xe)
  248. return 0;
  249. info->vector = vector;
  250. info->address = (high & 0xffff0000) | (low & 0x0000ffff);
  251. info->cs = low >> 16;
  252. info->flags = dpl;
  253. /* interrupt gates clear IF */
  254. if (type == 0xe)
  255. info->flags |= 4;
  256. return 1;
  257. }
  258. /* Locations of each CPU's IDT */
  259. static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc);
  260. /* Set an IDT entry. If the entry is part of the current IDT, then
  261. also update Xen. */
  262. static void xen_write_idt_entry(struct desc_struct *dt, int entrynum,
  263. u32 low, u32 high)
  264. {
  265. int cpu = smp_processor_id();
  266. unsigned long p = (unsigned long)&dt[entrynum];
  267. unsigned long start = per_cpu(idt_desc, cpu).address;
  268. unsigned long end = start + per_cpu(idt_desc, cpu).size + 1;
  269. xen_mc_flush();
  270. write_dt_entry(dt, entrynum, low, high);
  271. if (p >= start && (p + 8) <= end) {
  272. struct trap_info info[2];
  273. info[1].address = 0;
  274. if (cvt_gate_to_trap(entrynum, low, high, &info[0]))
  275. if (HYPERVISOR_set_trap_table(info))
  276. BUG();
  277. }
  278. }
  279. /* Load a new IDT into Xen. In principle this can be per-CPU, so we
  280. hold a spinlock to protect the static traps[] array (static because
  281. it avoids allocation, and saves stack space). */
  282. static void xen_load_idt(const struct Xgt_desc_struct *desc)
  283. {
  284. static DEFINE_SPINLOCK(lock);
  285. static struct trap_info traps[257];
  286. int cpu = smp_processor_id();
  287. unsigned in, out, count;
  288. per_cpu(idt_desc, cpu) = *desc;
  289. count = (desc->size+1) / 8;
  290. BUG_ON(count > 256);
  291. spin_lock(&lock);
  292. for (in = out = 0; in < count; in++) {
  293. const u32 *entry = (u32 *)(desc->address + in * 8);
  294. if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
  295. out++;
  296. }
  297. traps[out].address = 0;
  298. xen_mc_flush();
  299. if (HYPERVISOR_set_trap_table(traps))
  300. BUG();
  301. spin_unlock(&lock);
  302. }
  303. /* Write a GDT descriptor entry. Ignore LDT descriptors, since
  304. they're handled differently. */
  305. static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
  306. u32 low, u32 high)
  307. {
  308. switch ((high >> 8) & 0xff) {
  309. case DESCTYPE_LDT:
  310. case DESCTYPE_TSS:
  311. /* ignore */
  312. break;
  313. default: {
  314. xmaddr_t maddr = virt_to_machine(&dt[entry]);
  315. u64 desc = (u64)high << 32 | low;
  316. xen_mc_flush();
  317. if (HYPERVISOR_update_descriptor(maddr.maddr, desc))
  318. BUG();
  319. }
  320. }
  321. }
  322. static void xen_load_esp0(struct tss_struct *tss,
  323. struct thread_struct *thread)
  324. {
  325. struct multicall_space mcs = xen_mc_entry(0);
  326. MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->esp0);
  327. xen_mc_issue(PARAVIRT_LAZY_CPU);
  328. }
  329. static void xen_set_iopl_mask(unsigned mask)
  330. {
  331. struct physdev_set_iopl set_iopl;
  332. /* Force the change at ring 0. */
  333. set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
  334. HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
  335. }
  336. static void xen_io_delay(void)
  337. {
  338. }
  339. #ifdef CONFIG_X86_LOCAL_APIC
  340. static unsigned long xen_apic_read(unsigned long reg)
  341. {
  342. return 0;
  343. }
  344. #endif
  345. static void xen_flush_tlb(void)
  346. {
  347. struct mmuext_op op;
  348. op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
  349. if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
  350. BUG();
  351. }
  352. static void xen_flush_tlb_single(unsigned long addr)
  353. {
  354. struct mmuext_op op;
  355. op.cmd = MMUEXT_INVLPG_LOCAL;
  356. op.arg1.linear_addr = addr & PAGE_MASK;
  357. if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
  358. BUG();
  359. }
  360. static unsigned long xen_read_cr2(void)
  361. {
  362. return x86_read_percpu(xen_vcpu)->arch.cr2;
  363. }
  364. static void xen_write_cr4(unsigned long cr4)
  365. {
  366. /* never allow TSC to be disabled */
  367. native_write_cr4(cr4 & ~X86_CR4_TSD);
  368. }
  369. /*
  370. * Page-directory addresses above 4GB do not fit into architectural %cr3.
  371. * When accessing %cr3, or equivalent field in vcpu_guest_context, guests
  372. * must use the following accessor macros to pack/unpack valid MFNs.
  373. *
  374. * Note that Xen is using the fact that the pagetable base is always
  375. * page-aligned, and putting the 12 MSB of the address into the 12 LSB
  376. * of cr3.
  377. */
  378. #define xen_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn) >> 20))
  379. #define xen_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3) << 20))
  380. static unsigned long xen_read_cr3(void)
  381. {
  382. return x86_read_percpu(xen_cr3);
  383. }
  384. static void xen_write_cr3(unsigned long cr3)
  385. {
  386. if (cr3 == x86_read_percpu(xen_cr3)) {
  387. /* just a simple tlb flush */
  388. xen_flush_tlb();
  389. return;
  390. }
  391. x86_write_percpu(xen_cr3, cr3);
  392. {
  393. struct mmuext_op *op;
  394. struct multicall_space mcs = xen_mc_entry(sizeof(*op));
  395. unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
  396. op = mcs.args;
  397. op->cmd = MMUEXT_NEW_BASEPTR;
  398. op->arg1.mfn = mfn;
  399. MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
  400. xen_mc_issue(PARAVIRT_LAZY_CPU);
  401. }
  402. }
  403. static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
  404. {
  405. /* XXX pfn isn't necessarily a lowmem page */
  406. make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
  407. }
  408. static void xen_alloc_pd(u32 pfn)
  409. {
  410. make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
  411. }
  412. static void xen_release_pd(u32 pfn)
  413. {
  414. make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
  415. }
  416. static void xen_release_pt(u32 pfn)
  417. {
  418. make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
  419. }
  420. static void xen_alloc_pd_clone(u32 pfn, u32 clonepfn,
  421. u32 start, u32 count)
  422. {
  423. xen_alloc_pd(pfn);
  424. }
  425. static __init void xen_pagetable_setup_start(pgd_t *base)
  426. {
  427. pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
  428. init_mm.pgd = base;
  429. /*
  430. * copy top-level of Xen-supplied pagetable into place. For
  431. * !PAE we can use this as-is, but for PAE it is a stand-in
  432. * while we copy the pmd pages.
  433. */
  434. memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
  435. if (PTRS_PER_PMD > 1) {
  436. int i;
  437. /*
  438. * For PAE, need to allocate new pmds, rather than
  439. * share Xen's, since Xen doesn't like pmd's being
  440. * shared between address spaces.
  441. */
  442. for (i = 0; i < PTRS_PER_PGD; i++) {
  443. if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
  444. pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
  445. memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
  446. PAGE_SIZE);
  447. xen_alloc_pd(PFN_DOWN(__pa(pmd)));
  448. set_pgd(&base[i], __pgd(1 + __pa(pmd)));
  449. } else
  450. pgd_clear(&base[i]);
  451. }
  452. }
  453. /* make sure zero_page is mapped RO so we can use it in pagetables */
  454. make_lowmem_page_readonly(empty_zero_page);
  455. make_lowmem_page_readonly(base);
  456. /*
  457. * Switch to new pagetable. This is done before
  458. * pagetable_init has done anything so that the new pages
  459. * added to the table can be prepared properly for Xen.
  460. */
  461. xen_write_cr3(__pa(base));
  462. }
  463. static __init void xen_pagetable_setup_done(pgd_t *base)
  464. {
  465. if (!xen_feature(XENFEAT_auto_translated_physmap)) {
  466. /*
  467. * Create a mapping for the shared info page.
  468. * Should be set_fixmap(), but shared_info is a machine
  469. * address with no corresponding pseudo-phys address.
  470. */
  471. #if 0
  472. set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
  473. PFN_DOWN(xen_start_info->shared_info),
  474. PAGE_KERNEL);
  475. #endif
  476. HYPERVISOR_shared_info =
  477. (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
  478. } else
  479. HYPERVISOR_shared_info =
  480. (struct shared_info *)__va(xen_start_info->shared_info);
  481. #if 0
  482. xen_pgd_pin(base);
  483. #endif
  484. xen_vcpu_setup(smp_processor_id());
  485. }
  486. static const struct paravirt_ops xen_paravirt_ops __initdata = {
  487. .paravirt_enabled = 1,
  488. .shared_kernel_pmd = 0,
  489. .name = "Xen",
  490. .banner = xen_banner,
  491. .patch = paravirt_patch_default,
  492. .memory_setup = xen_memory_setup,
  493. .arch_setup = xen_arch_setup,
  494. .cpuid = xen_cpuid,
  495. .set_debugreg = xen_set_debugreg,
  496. .get_debugreg = xen_get_debugreg,
  497. .clts = native_clts,
  498. .read_cr0 = native_read_cr0,
  499. .write_cr0 = native_write_cr0,
  500. .read_cr2 = xen_read_cr2,
  501. .write_cr2 = native_write_cr2,
  502. .read_cr3 = xen_read_cr3,
  503. .write_cr3 = xen_write_cr3,
  504. .read_cr4 = native_read_cr4,
  505. .read_cr4_safe = native_read_cr4_safe,
  506. .write_cr4 = xen_write_cr4,
  507. .save_fl = xen_save_fl,
  508. .restore_fl = xen_restore_fl,
  509. .irq_disable = xen_irq_disable,
  510. .irq_enable = xen_irq_enable,
  511. .safe_halt = xen_safe_halt,
  512. .halt = xen_halt,
  513. .wbinvd = native_wbinvd,
  514. .read_msr = native_read_msr_safe,
  515. .write_msr = native_write_msr_safe,
  516. .read_tsc = native_read_tsc,
  517. .read_pmc = native_read_pmc,
  518. .iret = (void *)&hypercall_page[__HYPERVISOR_iret],
  519. .irq_enable_sysexit = NULL, /* never called */
  520. .load_tr_desc = paravirt_nop,
  521. .set_ldt = xen_set_ldt,
  522. .load_gdt = xen_load_gdt,
  523. .load_idt = xen_load_idt,
  524. .load_tls = xen_load_tls,
  525. .store_gdt = native_store_gdt,
  526. .store_idt = native_store_idt,
  527. .store_tr = xen_store_tr,
  528. .write_ldt_entry = xen_write_ldt_entry,
  529. .write_gdt_entry = xen_write_gdt_entry,
  530. .write_idt_entry = xen_write_idt_entry,
  531. .load_esp0 = xen_load_esp0,
  532. .set_iopl_mask = xen_set_iopl_mask,
  533. .io_delay = xen_io_delay,
  534. #ifdef CONFIG_X86_LOCAL_APIC
  535. .apic_write = paravirt_nop,
  536. .apic_write_atomic = paravirt_nop,
  537. .apic_read = xen_apic_read,
  538. .setup_boot_clock = paravirt_nop,
  539. .setup_secondary_clock = paravirt_nop,
  540. .startup_ipi_hook = paravirt_nop,
  541. #endif
  542. .flush_tlb_user = xen_flush_tlb,
  543. .flush_tlb_kernel = xen_flush_tlb,
  544. .flush_tlb_single = xen_flush_tlb_single,
  545. .pte_update = paravirt_nop,
  546. .pte_update_defer = paravirt_nop,
  547. .pagetable_setup_start = xen_pagetable_setup_start,
  548. .pagetable_setup_done = xen_pagetable_setup_done,
  549. .alloc_pt = xen_alloc_pt,
  550. .alloc_pd = xen_alloc_pd,
  551. .alloc_pd_clone = xen_alloc_pd_clone,
  552. .release_pd = xen_release_pd,
  553. .release_pt = xen_release_pt,
  554. .set_lazy_mode = xen_set_lazy_mode,
  555. };
  556. /* First C function to be called on Xen boot */
  557. asmlinkage void __init xen_start_kernel(void)
  558. {
  559. pgd_t *pgd;
  560. if (!xen_start_info)
  561. return;
  562. BUG_ON(memcmp(xen_start_info->magic, "xen-3.0", 7) != 0);
  563. /* Install Xen paravirt ops */
  564. paravirt_ops = xen_paravirt_ops;
  565. xen_setup_features();
  566. /* Get mfn list */
  567. if (!xen_feature(XENFEAT_auto_translated_physmap))
  568. phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
  569. pgd = (pgd_t *)xen_start_info->pt_base;
  570. init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
  571. init_mm.pgd = pgd; /* use the Xen pagetables to start */
  572. /* keep using Xen gdt for now; no urgent need to change it */
  573. x86_write_percpu(xen_cr3, __pa(pgd));
  574. xen_vcpu_setup(0);
  575. paravirt_ops.kernel_rpl = 1;
  576. if (xen_feature(XENFEAT_supervisor_mode_kernel))
  577. paravirt_ops.kernel_rpl = 0;
  578. /* set the limit of our address space */
  579. reserve_top_address(-HYPERVISOR_VIRT_START + 2 * PAGE_SIZE);
  580. /* set up basic CPUID stuff */
  581. cpu_detect(&new_cpu_data);
  582. new_cpu_data.hard_math = 1;
  583. new_cpu_data.x86_capability[0] = cpuid_edx(1);
  584. /* Poke various useful things into boot_params */
  585. LOADER_TYPE = (9 << 4) | 0;
  586. INITRD_START = xen_start_info->mod_start ? __pa(xen_start_info->mod_start) : 0;
  587. INITRD_SIZE = xen_start_info->mod_len;
  588. /* Start the world */
  589. start_kernel();
  590. }