enlighten.c 32 KB

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