lguest.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /*
  2. * Lguest specific paravirt-ops implementation
  3. *
  4. * Copyright (C) 2006, Rusty Russell <rusty@rustcorp.com.au> IBM Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  14. * NON INFRINGEMENT. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/start_kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/console.h>
  25. #include <linux/screen_info.h>
  26. #include <linux/irq.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/clocksource.h>
  29. #include <linux/clockchips.h>
  30. #include <linux/lguest.h>
  31. #include <linux/lguest_launcher.h>
  32. #include <linux/lguest_bus.h>
  33. #include <asm/paravirt.h>
  34. #include <asm/param.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/desc.h>
  38. #include <asm/setup.h>
  39. #include <asm/e820.h>
  40. #include <asm/mce.h>
  41. #include <asm/io.h>
  42. /* Declarations for definitions in lguest_guest.S */
  43. extern char lguest_noirq_start[], lguest_noirq_end[];
  44. extern const char lgstart_cli[], lgend_cli[];
  45. extern const char lgstart_sti[], lgend_sti[];
  46. extern const char lgstart_popf[], lgend_popf[];
  47. extern const char lgstart_pushf[], lgend_pushf[];
  48. extern const char lgstart_iret[], lgend_iret[];
  49. extern void lguest_iret(void);
  50. struct lguest_data lguest_data = {
  51. .hcall_status = { [0 ... LHCALL_RING_SIZE-1] = 0xFF },
  52. .noirq_start = (u32)lguest_noirq_start,
  53. .noirq_end = (u32)lguest_noirq_end,
  54. .blocked_interrupts = { 1 }, /* Block timer interrupts */
  55. };
  56. struct lguest_device_desc *lguest_devices;
  57. static cycle_t clock_base;
  58. static enum paravirt_lazy_mode lazy_mode;
  59. static void lguest_lazy_mode(enum paravirt_lazy_mode mode)
  60. {
  61. if (mode == PARAVIRT_LAZY_FLUSH) {
  62. if (unlikely(lazy_mode != PARAVIRT_LAZY_NONE))
  63. hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0);
  64. } else {
  65. lazy_mode = mode;
  66. if (mode == PARAVIRT_LAZY_NONE)
  67. hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0);
  68. }
  69. }
  70. static void lazy_hcall(unsigned long call,
  71. unsigned long arg1,
  72. unsigned long arg2,
  73. unsigned long arg3)
  74. {
  75. if (lazy_mode == PARAVIRT_LAZY_NONE)
  76. hcall(call, arg1, arg2, arg3);
  77. else
  78. async_hcall(call, arg1, arg2, arg3);
  79. }
  80. void async_hcall(unsigned long call,
  81. unsigned long arg1, unsigned long arg2, unsigned long arg3)
  82. {
  83. /* Note: This code assumes we're uniprocessor. */
  84. static unsigned int next_call;
  85. unsigned long flags;
  86. local_irq_save(flags);
  87. if (lguest_data.hcall_status[next_call] != 0xFF) {
  88. /* Table full, so do normal hcall which will flush table. */
  89. hcall(call, arg1, arg2, arg3);
  90. } else {
  91. lguest_data.hcalls[next_call].eax = call;
  92. lguest_data.hcalls[next_call].edx = arg1;
  93. lguest_data.hcalls[next_call].ebx = arg2;
  94. lguest_data.hcalls[next_call].ecx = arg3;
  95. /* Make sure host sees arguments before "valid" flag. */
  96. wmb();
  97. lguest_data.hcall_status[next_call] = 0;
  98. if (++next_call == LHCALL_RING_SIZE)
  99. next_call = 0;
  100. }
  101. local_irq_restore(flags);
  102. }
  103. void lguest_send_dma(unsigned long key, struct lguest_dma *dma)
  104. {
  105. dma->used_len = 0;
  106. hcall(LHCALL_SEND_DMA, key, __pa(dma), 0);
  107. }
  108. int lguest_bind_dma(unsigned long key, struct lguest_dma *dmas,
  109. unsigned int num, u8 irq)
  110. {
  111. if (!hcall(LHCALL_BIND_DMA, key, __pa(dmas), (num << 8) | irq))
  112. return -ENOMEM;
  113. return 0;
  114. }
  115. void lguest_unbind_dma(unsigned long key, struct lguest_dma *dmas)
  116. {
  117. hcall(LHCALL_BIND_DMA, key, __pa(dmas), 0);
  118. }
  119. /* For guests, device memory can be used as normal memory, so we cast away the
  120. * __iomem to quieten sparse. */
  121. void *lguest_map(unsigned long phys_addr, unsigned long pages)
  122. {
  123. return (__force void *)ioremap(phys_addr, PAGE_SIZE*pages);
  124. }
  125. void lguest_unmap(void *addr)
  126. {
  127. iounmap((__force void __iomem *)addr);
  128. }
  129. static unsigned long save_fl(void)
  130. {
  131. return lguest_data.irq_enabled;
  132. }
  133. static void restore_fl(unsigned long flags)
  134. {
  135. /* FIXME: Check if interrupt pending... */
  136. lguest_data.irq_enabled = flags;
  137. }
  138. static void irq_disable(void)
  139. {
  140. lguest_data.irq_enabled = 0;
  141. }
  142. static void irq_enable(void)
  143. {
  144. /* FIXME: Check if interrupt pending... */
  145. lguest_data.irq_enabled = X86_EFLAGS_IF;
  146. }
  147. static void lguest_write_idt_entry(struct desc_struct *dt,
  148. int entrynum, u32 low, u32 high)
  149. {
  150. write_dt_entry(dt, entrynum, low, high);
  151. hcall(LHCALL_LOAD_IDT_ENTRY, entrynum, low, high);
  152. }
  153. static void lguest_load_idt(const struct Xgt_desc_struct *desc)
  154. {
  155. unsigned int i;
  156. struct desc_struct *idt = (void *)desc->address;
  157. for (i = 0; i < (desc->size+1)/8; i++)
  158. hcall(LHCALL_LOAD_IDT_ENTRY, i, idt[i].a, idt[i].b);
  159. }
  160. static void lguest_load_gdt(const struct Xgt_desc_struct *desc)
  161. {
  162. BUG_ON((desc->size+1)/8 != GDT_ENTRIES);
  163. hcall(LHCALL_LOAD_GDT, __pa(desc->address), GDT_ENTRIES, 0);
  164. }
  165. static void lguest_write_gdt_entry(struct desc_struct *dt,
  166. int entrynum, u32 low, u32 high)
  167. {
  168. write_dt_entry(dt, entrynum, low, high);
  169. hcall(LHCALL_LOAD_GDT, __pa(dt), GDT_ENTRIES, 0);
  170. }
  171. static void lguest_load_tls(struct thread_struct *t, unsigned int cpu)
  172. {
  173. lazy_hcall(LHCALL_LOAD_TLS, __pa(&t->tls_array), cpu, 0);
  174. }
  175. static void lguest_set_ldt(const void *addr, unsigned entries)
  176. {
  177. }
  178. static void lguest_load_tr_desc(void)
  179. {
  180. }
  181. static void lguest_cpuid(unsigned int *eax, unsigned int *ebx,
  182. unsigned int *ecx, unsigned int *edx)
  183. {
  184. int function = *eax;
  185. native_cpuid(eax, ebx, ecx, edx);
  186. switch (function) {
  187. case 1: /* Basic feature request. */
  188. /* We only allow kernel to see SSE3, CMPXCHG16B and SSSE3 */
  189. *ecx &= 0x00002201;
  190. /* SSE, SSE2, FXSR, MMX, CMOV, CMPXCHG8B, FPU. */
  191. *edx &= 0x07808101;
  192. /* Host wants to know when we flush kernel pages: set PGE. */
  193. *edx |= 0x00002000;
  194. break;
  195. case 0x80000000:
  196. /* Futureproof this a little: if they ask how much extended
  197. * processor information, limit it to known fields. */
  198. if (*eax > 0x80000008)
  199. *eax = 0x80000008;
  200. break;
  201. }
  202. }
  203. static unsigned long current_cr0, current_cr3;
  204. static void lguest_write_cr0(unsigned long val)
  205. {
  206. lazy_hcall(LHCALL_TS, val & 8, 0, 0);
  207. current_cr0 = val;
  208. }
  209. static unsigned long lguest_read_cr0(void)
  210. {
  211. return current_cr0;
  212. }
  213. static void lguest_clts(void)
  214. {
  215. lazy_hcall(LHCALL_TS, 0, 0, 0);
  216. current_cr0 &= ~8U;
  217. }
  218. static unsigned long lguest_read_cr2(void)
  219. {
  220. return lguest_data.cr2;
  221. }
  222. static void lguest_write_cr3(unsigned long cr3)
  223. {
  224. lazy_hcall(LHCALL_NEW_PGTABLE, cr3, 0, 0);
  225. current_cr3 = cr3;
  226. }
  227. static unsigned long lguest_read_cr3(void)
  228. {
  229. return current_cr3;
  230. }
  231. /* Used to enable/disable PGE, but we don't care. */
  232. static unsigned long lguest_read_cr4(void)
  233. {
  234. return 0;
  235. }
  236. static void lguest_write_cr4(unsigned long val)
  237. {
  238. }
  239. static void lguest_set_pte_at(struct mm_struct *mm, unsigned long addr,
  240. pte_t *ptep, pte_t pteval)
  241. {
  242. *ptep = pteval;
  243. lazy_hcall(LHCALL_SET_PTE, __pa(mm->pgd), addr, pteval.pte_low);
  244. }
  245. /* We only support two-level pagetables at the moment. */
  246. static void lguest_set_pmd(pmd_t *pmdp, pmd_t pmdval)
  247. {
  248. *pmdp = pmdval;
  249. lazy_hcall(LHCALL_SET_PMD, __pa(pmdp)&PAGE_MASK,
  250. (__pa(pmdp)&(PAGE_SIZE-1))/4, 0);
  251. }
  252. /* FIXME: Eliminate all callers of this. */
  253. static void lguest_set_pte(pte_t *ptep, pte_t pteval)
  254. {
  255. *ptep = pteval;
  256. /* Don't bother with hypercall before initial setup. */
  257. if (current_cr3)
  258. lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0);
  259. }
  260. static void lguest_flush_tlb_single(unsigned long addr)
  261. {
  262. /* Simply set it to zero, and it will fault back in. */
  263. lazy_hcall(LHCALL_SET_PTE, current_cr3, addr, 0);
  264. }
  265. static void lguest_flush_tlb_user(void)
  266. {
  267. lazy_hcall(LHCALL_FLUSH_TLB, 0, 0, 0);
  268. }
  269. static void lguest_flush_tlb_kernel(void)
  270. {
  271. lazy_hcall(LHCALL_FLUSH_TLB, 1, 0, 0);
  272. }
  273. static void disable_lguest_irq(unsigned int irq)
  274. {
  275. set_bit(irq, lguest_data.blocked_interrupts);
  276. }
  277. static void enable_lguest_irq(unsigned int irq)
  278. {
  279. clear_bit(irq, lguest_data.blocked_interrupts);
  280. /* FIXME: If it's pending? */
  281. }
  282. static struct irq_chip lguest_irq_controller = {
  283. .name = "lguest",
  284. .mask = disable_lguest_irq,
  285. .mask_ack = disable_lguest_irq,
  286. .unmask = enable_lguest_irq,
  287. };
  288. static void __init lguest_init_IRQ(void)
  289. {
  290. unsigned int i;
  291. for (i = 0; i < LGUEST_IRQS; i++) {
  292. int vector = FIRST_EXTERNAL_VECTOR + i;
  293. if (vector != SYSCALL_VECTOR) {
  294. set_intr_gate(vector, interrupt[i]);
  295. set_irq_chip_and_handler(i, &lguest_irq_controller,
  296. handle_level_irq);
  297. }
  298. }
  299. irq_ctx_init(smp_processor_id());
  300. }
  301. static unsigned long lguest_get_wallclock(void)
  302. {
  303. return hcall(LHCALL_GET_WALLCLOCK, 0, 0, 0);
  304. }
  305. static cycle_t lguest_clock_read(void)
  306. {
  307. if (lguest_data.tsc_khz)
  308. return native_read_tsc();
  309. else
  310. return jiffies;
  311. }
  312. /* This is what we tell the kernel is our clocksource. */
  313. static struct clocksource lguest_clock = {
  314. .name = "lguest",
  315. .rating = 400,
  316. .read = lguest_clock_read,
  317. };
  318. static unsigned long long lguest_sched_clock(void)
  319. {
  320. return cyc2ns(&lguest_clock, lguest_clock_read() - clock_base);
  321. }
  322. /* We also need a "struct clock_event_device": Linux asks us to set it to go
  323. * off some time in the future. Actually, James Morris figured all this out, I
  324. * just applied the patch. */
  325. static int lguest_clockevent_set_next_event(unsigned long delta,
  326. struct clock_event_device *evt)
  327. {
  328. if (delta < LG_CLOCK_MIN_DELTA) {
  329. if (printk_ratelimit())
  330. printk(KERN_DEBUG "%s: small delta %lu ns\n",
  331. __FUNCTION__, delta);
  332. return -ETIME;
  333. }
  334. hcall(LHCALL_SET_CLOCKEVENT, delta, 0, 0);
  335. return 0;
  336. }
  337. static void lguest_clockevent_set_mode(enum clock_event_mode mode,
  338. struct clock_event_device *evt)
  339. {
  340. switch (mode) {
  341. case CLOCK_EVT_MODE_UNUSED:
  342. case CLOCK_EVT_MODE_SHUTDOWN:
  343. /* A 0 argument shuts the clock down. */
  344. hcall(LHCALL_SET_CLOCKEVENT, 0, 0, 0);
  345. break;
  346. case CLOCK_EVT_MODE_ONESHOT:
  347. /* This is what we expect. */
  348. break;
  349. case CLOCK_EVT_MODE_PERIODIC:
  350. BUG();
  351. case CLOCK_EVT_MODE_RESUME:
  352. break;
  353. }
  354. }
  355. /* This describes our primitive timer chip. */
  356. static struct clock_event_device lguest_clockevent = {
  357. .name = "lguest",
  358. .features = CLOCK_EVT_FEAT_ONESHOT,
  359. .set_next_event = lguest_clockevent_set_next_event,
  360. .set_mode = lguest_clockevent_set_mode,
  361. .rating = INT_MAX,
  362. .mult = 1,
  363. .shift = 0,
  364. .min_delta_ns = LG_CLOCK_MIN_DELTA,
  365. .max_delta_ns = LG_CLOCK_MAX_DELTA,
  366. };
  367. /* This is the Guest timer interrupt handler (hardware interrupt 0). We just
  368. * call the clockevent infrastructure and it does whatever needs doing. */
  369. static void lguest_time_irq(unsigned int irq, struct irq_desc *desc)
  370. {
  371. unsigned long flags;
  372. /* Don't interrupt us while this is running. */
  373. local_irq_save(flags);
  374. lguest_clockevent.event_handler(&lguest_clockevent);
  375. local_irq_restore(flags);
  376. }
  377. static void lguest_time_init(void)
  378. {
  379. set_irq_handler(0, lguest_time_irq);
  380. /* We use the TSC if the Host tells us we can, otherwise a dumb
  381. * jiffies-based clock. */
  382. if (lguest_data.tsc_khz) {
  383. lguest_clock.shift = 22;
  384. lguest_clock.mult = clocksource_khz2mult(lguest_data.tsc_khz,
  385. lguest_clock.shift);
  386. lguest_clock.mask = CLOCKSOURCE_MASK(64);
  387. lguest_clock.flags = CLOCK_SOURCE_IS_CONTINUOUS;
  388. } else {
  389. /* To understand this, start at kernel/time/jiffies.c... */
  390. lguest_clock.shift = 8;
  391. lguest_clock.mult = (((u64)NSEC_PER_SEC<<8)/ACTHZ) << 8;
  392. lguest_clock.mask = CLOCKSOURCE_MASK(32);
  393. }
  394. clock_base = lguest_clock_read();
  395. clocksource_register(&lguest_clock);
  396. /* We can't set cpumask in the initializer: damn C limitations! */
  397. lguest_clockevent.cpumask = cpumask_of_cpu(0);
  398. clockevents_register_device(&lguest_clockevent);
  399. enable_lguest_irq(0);
  400. }
  401. static void lguest_load_esp0(struct tss_struct *tss,
  402. struct thread_struct *thread)
  403. {
  404. lazy_hcall(LHCALL_SET_STACK, __KERNEL_DS|0x1, thread->esp0,
  405. THREAD_SIZE/PAGE_SIZE);
  406. }
  407. static void lguest_set_debugreg(int regno, unsigned long value)
  408. {
  409. /* FIXME: Implement */
  410. }
  411. static void lguest_wbinvd(void)
  412. {
  413. }
  414. #ifdef CONFIG_X86_LOCAL_APIC
  415. static void lguest_apic_write(unsigned long reg, unsigned long v)
  416. {
  417. }
  418. static unsigned long lguest_apic_read(unsigned long reg)
  419. {
  420. return 0;
  421. }
  422. #endif
  423. static void lguest_safe_halt(void)
  424. {
  425. hcall(LHCALL_HALT, 0, 0, 0);
  426. }
  427. static void lguest_power_off(void)
  428. {
  429. hcall(LHCALL_CRASH, __pa("Power down"), 0, 0);
  430. }
  431. static int lguest_panic(struct notifier_block *nb, unsigned long l, void *p)
  432. {
  433. hcall(LHCALL_CRASH, __pa(p), 0, 0);
  434. return NOTIFY_DONE;
  435. }
  436. static struct notifier_block paniced = {
  437. .notifier_call = lguest_panic
  438. };
  439. static __init char *lguest_memory_setup(void)
  440. {
  441. /* We do this here because lockcheck barfs if before start_kernel */
  442. atomic_notifier_chain_register(&panic_notifier_list, &paniced);
  443. add_memory_region(E820_MAP->addr, E820_MAP->size, E820_MAP->type);
  444. return "LGUEST";
  445. }
  446. static const struct lguest_insns
  447. {
  448. const char *start, *end;
  449. } lguest_insns[] = {
  450. [PARAVIRT_PATCH(irq_disable)] = { lgstart_cli, lgend_cli },
  451. [PARAVIRT_PATCH(irq_enable)] = { lgstart_sti, lgend_sti },
  452. [PARAVIRT_PATCH(restore_fl)] = { lgstart_popf, lgend_popf },
  453. [PARAVIRT_PATCH(save_fl)] = { lgstart_pushf, lgend_pushf },
  454. };
  455. static unsigned lguest_patch(u8 type, u16 clobber, void *insns, unsigned len)
  456. {
  457. unsigned int insn_len;
  458. /* Don't touch it if we don't have a replacement */
  459. if (type >= ARRAY_SIZE(lguest_insns) || !lguest_insns[type].start)
  460. return paravirt_patch_default(type, clobber, insns, len);
  461. insn_len = lguest_insns[type].end - lguest_insns[type].start;
  462. /* Similarly if we can't fit replacement. */
  463. if (len < insn_len)
  464. return paravirt_patch_default(type, clobber, insns, len);
  465. memcpy(insns, lguest_insns[type].start, insn_len);
  466. return insn_len;
  467. }
  468. __init void lguest_init(void *boot)
  469. {
  470. /* Copy boot parameters first. */
  471. memcpy(&boot_params, boot, PARAM_SIZE);
  472. memcpy(boot_command_line, __va(boot_params.hdr.cmd_line_ptr),
  473. COMMAND_LINE_SIZE);
  474. paravirt_ops.name = "lguest";
  475. paravirt_ops.paravirt_enabled = 1;
  476. paravirt_ops.kernel_rpl = 1;
  477. paravirt_ops.save_fl = save_fl;
  478. paravirt_ops.restore_fl = restore_fl;
  479. paravirt_ops.irq_disable = irq_disable;
  480. paravirt_ops.irq_enable = irq_enable;
  481. paravirt_ops.load_gdt = lguest_load_gdt;
  482. paravirt_ops.memory_setup = lguest_memory_setup;
  483. paravirt_ops.cpuid = lguest_cpuid;
  484. paravirt_ops.write_cr3 = lguest_write_cr3;
  485. paravirt_ops.flush_tlb_user = lguest_flush_tlb_user;
  486. paravirt_ops.flush_tlb_single = lguest_flush_tlb_single;
  487. paravirt_ops.flush_tlb_kernel = lguest_flush_tlb_kernel;
  488. paravirt_ops.set_pte = lguest_set_pte;
  489. paravirt_ops.set_pte_at = lguest_set_pte_at;
  490. paravirt_ops.set_pmd = lguest_set_pmd;
  491. #ifdef CONFIG_X86_LOCAL_APIC
  492. paravirt_ops.apic_write = lguest_apic_write;
  493. paravirt_ops.apic_write_atomic = lguest_apic_write;
  494. paravirt_ops.apic_read = lguest_apic_read;
  495. #endif
  496. paravirt_ops.load_idt = lguest_load_idt;
  497. paravirt_ops.iret = lguest_iret;
  498. paravirt_ops.load_esp0 = lguest_load_esp0;
  499. paravirt_ops.load_tr_desc = lguest_load_tr_desc;
  500. paravirt_ops.set_ldt = lguest_set_ldt;
  501. paravirt_ops.load_tls = lguest_load_tls;
  502. paravirt_ops.set_debugreg = lguest_set_debugreg;
  503. paravirt_ops.clts = lguest_clts;
  504. paravirt_ops.read_cr0 = lguest_read_cr0;
  505. paravirt_ops.write_cr0 = lguest_write_cr0;
  506. paravirt_ops.init_IRQ = lguest_init_IRQ;
  507. paravirt_ops.read_cr2 = lguest_read_cr2;
  508. paravirt_ops.read_cr3 = lguest_read_cr3;
  509. paravirt_ops.read_cr4 = lguest_read_cr4;
  510. paravirt_ops.write_cr4 = lguest_write_cr4;
  511. paravirt_ops.write_gdt_entry = lguest_write_gdt_entry;
  512. paravirt_ops.write_idt_entry = lguest_write_idt_entry;
  513. paravirt_ops.patch = lguest_patch;
  514. paravirt_ops.safe_halt = lguest_safe_halt;
  515. paravirt_ops.get_wallclock = lguest_get_wallclock;
  516. paravirt_ops.time_init = lguest_time_init;
  517. paravirt_ops.set_lazy_mode = lguest_lazy_mode;
  518. paravirt_ops.wbinvd = lguest_wbinvd;
  519. paravirt_ops.sched_clock = lguest_sched_clock;
  520. hcall(LHCALL_LGUEST_INIT, __pa(&lguest_data), 0, 0);
  521. /* We use top of mem for initial pagetables. */
  522. init_pg_tables_end = __pa(pg0);
  523. asm volatile ("mov %0, %%fs" : : "r" (__KERNEL_DS) : "memory");
  524. reserve_top_address(lguest_data.reserve_mem);
  525. lockdep_init();
  526. paravirt_disable_iospace();
  527. cpu_detect(&new_cpu_data);
  528. /* head.S usually sets up the first capability word, so do it here. */
  529. new_cpu_data.x86_capability[0] = cpuid_edx(1);
  530. /* Math is always hard! */
  531. new_cpu_data.hard_math = 1;
  532. #ifdef CONFIG_X86_MCE
  533. mce_disabled = 1;
  534. #endif
  535. #ifdef CONFIG_ACPI
  536. acpi_disabled = 1;
  537. acpi_ht = 0;
  538. #endif
  539. add_preferred_console("hvc", 0, NULL);
  540. pm_power_off = lguest_power_off;
  541. start_kernel();
  542. }