enlighten.c 18 KB

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