2 * Core of Xen paravirt_ops implementation.
4 * This file contains the xen_paravirt_ops structure itself, and the
6 * - privileged instructions
11 * Jeremy Fitzhardinge <jeremy@xensource.com>, XenSource Inc, 2007
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/smp.h>
17 #include <linux/preempt.h>
18 #include <linux/hardirq.h>
19 #include <linux/percpu.h>
20 #include <linux/delay.h>
21 #include <linux/start_kernel.h>
22 #include <linux/sched.h>
23 #include <linux/bootmem.h>
24 #include <linux/module.h>
26 #include <linux/page-flags.h>
27 #include <linux/highmem.h>
28 #include <linux/smp.h>
30 #include <xen/interface/xen.h>
31 #include <xen/interface/physdev.h>
32 #include <xen/interface/vcpu.h>
33 #include <xen/features.h>
36 #include <asm/paravirt.h>
38 #include <asm/xen/hypercall.h>
39 #include <asm/xen/hypervisor.h>
40 #include <asm/fixmap.h>
41 #include <asm/processor.h>
42 #include <asm/setup.h>
44 #include <asm/pgtable.h>
45 #include <asm/tlbflush.h>
49 #include "multicalls.h"
51 EXPORT_SYMBOL_GPL(hypercall_page);
53 DEFINE_PER_CPU(enum paravirt_lazy_mode, xen_lazy_mode);
55 DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);
56 DEFINE_PER_CPU(struct vcpu_info, xen_vcpu_info);
57 DEFINE_PER_CPU(unsigned long, xen_cr3);
59 struct start_info *xen_start_info;
60 EXPORT_SYMBOL_GPL(xen_start_info);
62 void xen_vcpu_setup(int cpu)
64 per_cpu(xen_vcpu, cpu) = &HYPERVISOR_shared_info->vcpu_info[cpu];
67 static void __init xen_banner(void)
69 printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
71 printk(KERN_INFO "Hypervisor signature: %s\n", xen_start_info->magic);
74 static void xen_cpuid(unsigned int *eax, unsigned int *ebx,
75 unsigned int *ecx, unsigned int *edx)
77 unsigned maskedx = ~0;
80 * Mask out inconvenient features, to try and disable as many
81 * unsupported kernel subsystems as possible.
84 maskedx = ~((1 << X86_FEATURE_APIC) | /* disable APIC */
85 (1 << X86_FEATURE_ACPI) | /* disable ACPI */
86 (1 << X86_FEATURE_ACC)); /* thermal monitoring */
88 asm(XEN_EMULATE_PREFIX "cpuid"
93 : "0" (*eax), "2" (*ecx));
97 static void xen_set_debugreg(int reg, unsigned long val)
99 HYPERVISOR_set_debugreg(reg, val);
102 static unsigned long xen_get_debugreg(int reg)
104 return HYPERVISOR_get_debugreg(reg);
107 static unsigned long xen_save_fl(void)
109 struct vcpu_info *vcpu;
112 vcpu = x86_read_percpu(xen_vcpu);
114 /* flag has opposite sense of mask */
115 flags = !vcpu->evtchn_upcall_mask;
117 /* convert to IF type flag
121 return (-flags) & X86_EFLAGS_IF;
124 static void xen_restore_fl(unsigned long flags)
126 struct vcpu_info *vcpu;
128 /* convert from IF type flag */
129 flags = !(flags & X86_EFLAGS_IF);
131 /* There's a one instruction preempt window here. We need to
132 make sure we're don't switch CPUs between getting the vcpu
133 pointer and updating the mask. */
135 vcpu = x86_read_percpu(xen_vcpu);
136 vcpu->evtchn_upcall_mask = flags;
137 preempt_enable_no_resched();
139 /* Doesn't matter if we get preempted here, because any
140 pending event will get dealt with anyway. */
143 preempt_check_resched();
144 barrier(); /* unmask then check (avoid races) */
145 if (unlikely(vcpu->evtchn_upcall_pending))
146 force_evtchn_callback();
150 static void xen_irq_disable(void)
152 /* There's a one instruction preempt window here. We need to
153 make sure we're don't switch CPUs between getting the vcpu
154 pointer and updating the mask. */
156 x86_read_percpu(xen_vcpu)->evtchn_upcall_mask = 1;
157 preempt_enable_no_resched();
160 static void xen_irq_enable(void)
162 struct vcpu_info *vcpu;
164 /* There's a one instruction preempt window here. We need to
165 make sure we're don't switch CPUs between getting the vcpu
166 pointer and updating the mask. */
168 vcpu = x86_read_percpu(xen_vcpu);
169 vcpu->evtchn_upcall_mask = 0;
170 preempt_enable_no_resched();
172 /* Doesn't matter if we get preempted here, because any
173 pending event will get dealt with anyway. */
175 barrier(); /* unmask then check (avoid races) */
176 if (unlikely(vcpu->evtchn_upcall_pending))
177 force_evtchn_callback();
180 static void xen_safe_halt(void)
182 /* Blocking includes an implicit local_irq_enable(). */
183 if (HYPERVISOR_sched_op(SCHEDOP_block, 0) != 0)
187 static void xen_halt(void)
190 HYPERVISOR_vcpu_op(VCPUOP_down, smp_processor_id(), NULL);
195 static void xen_set_lazy_mode(enum paravirt_lazy_mode mode)
197 BUG_ON(preemptible());
200 case PARAVIRT_LAZY_NONE:
201 BUG_ON(x86_read_percpu(xen_lazy_mode) == PARAVIRT_LAZY_NONE);
204 case PARAVIRT_LAZY_MMU:
205 case PARAVIRT_LAZY_CPU:
206 BUG_ON(x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE);
209 case PARAVIRT_LAZY_FLUSH:
210 /* flush if necessary, but don't change state */
211 if (x86_read_percpu(xen_lazy_mode) != PARAVIRT_LAZY_NONE)
217 x86_write_percpu(xen_lazy_mode, mode);
220 static unsigned long xen_store_tr(void)
225 static void xen_set_ldt(const void *addr, unsigned entries)
227 unsigned long linear_addr = (unsigned long)addr;
228 struct mmuext_op *op;
229 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
232 op->cmd = MMUEXT_SET_LDT;
234 /* ldt my be vmalloced, use arbitrary_virt_to_machine */
236 maddr = arbitrary_virt_to_machine((unsigned long)addr);
237 linear_addr = (unsigned long)maddr.maddr;
239 op->arg1.linear_addr = linear_addr;
240 op->arg2.nr_ents = entries;
242 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
244 xen_mc_issue(PARAVIRT_LAZY_CPU);
247 static void xen_load_gdt(const struct Xgt_desc_struct *dtr)
249 unsigned long *frames;
250 unsigned long va = dtr->address;
251 unsigned int size = dtr->size + 1;
252 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
254 struct multicall_space mcs;
256 /* A GDT can be up to 64k in size, which corresponds to 8192
257 8-byte entries, or 16 4k pages.. */
259 BUG_ON(size > 65536);
260 BUG_ON(va & ~PAGE_MASK);
262 mcs = xen_mc_entry(sizeof(*frames) * pages);
265 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
266 frames[f] = virt_to_mfn(va);
267 make_lowmem_page_readonly((void *)va);
270 MULTI_set_gdt(mcs.mc, frames, size / sizeof(struct desc_struct));
272 xen_mc_issue(PARAVIRT_LAZY_CPU);
275 static void load_TLS_descriptor(struct thread_struct *t,
276 unsigned int cpu, unsigned int i)
278 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
279 xmaddr_t maddr = virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
280 struct multicall_space mc = __xen_mc_entry(0);
282 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);
285 static void xen_load_tls(struct thread_struct *t, unsigned int cpu)
289 load_TLS_descriptor(t, cpu, 0);
290 load_TLS_descriptor(t, cpu, 1);
291 load_TLS_descriptor(t, cpu, 2);
293 xen_mc_issue(PARAVIRT_LAZY_CPU);
296 static void xen_write_ldt_entry(struct desc_struct *dt, int entrynum,
299 unsigned long lp = (unsigned long)&dt[entrynum];
300 xmaddr_t mach_lp = virt_to_machine(lp);
301 u64 entry = (u64)high << 32 | low;
306 if (HYPERVISOR_update_descriptor(mach_lp.maddr, entry))
312 static int cvt_gate_to_trap(int vector, u32 low, u32 high,
313 struct trap_info *info)
317 type = (high >> 8) & 0x1f;
318 dpl = (high >> 13) & 3;
320 if (type != 0xf && type != 0xe)
323 info->vector = vector;
324 info->address = (high & 0xffff0000) | (low & 0x0000ffff);
325 info->cs = low >> 16;
327 /* interrupt gates clear IF */
334 /* Locations of each CPU's IDT */
335 static DEFINE_PER_CPU(struct Xgt_desc_struct, idt_desc);
337 /* Set an IDT entry. If the entry is part of the current IDT, then
339 static void xen_write_idt_entry(struct desc_struct *dt, int entrynum,
342 unsigned long p = (unsigned long)&dt[entrynum];
343 unsigned long start, end;
347 start = __get_cpu_var(idt_desc).address;
348 end = start + __get_cpu_var(idt_desc).size + 1;
352 write_dt_entry(dt, entrynum, low, high);
354 if (p >= start && (p + 8) <= end) {
355 struct trap_info info[2];
359 if (cvt_gate_to_trap(entrynum, low, high, &info[0]))
360 if (HYPERVISOR_set_trap_table(info))
367 static void xen_convert_trap_info(const struct Xgt_desc_struct *desc,
368 struct trap_info *traps)
370 unsigned in, out, count;
372 count = (desc->size+1) / 8;
375 for (in = out = 0; in < count; in++) {
376 const u32 *entry = (u32 *)(desc->address + in * 8);
378 if (cvt_gate_to_trap(in, entry[0], entry[1], &traps[out]))
381 traps[out].address = 0;
384 void xen_copy_trap_info(struct trap_info *traps)
386 const struct Xgt_desc_struct *desc = &__get_cpu_var(idt_desc);
388 xen_convert_trap_info(desc, traps);
391 /* Load a new IDT into Xen. In principle this can be per-CPU, so we
392 hold a spinlock to protect the static traps[] array (static because
393 it avoids allocation, and saves stack space). */
394 static void xen_load_idt(const struct Xgt_desc_struct *desc)
396 static DEFINE_SPINLOCK(lock);
397 static struct trap_info traps[257];
401 __get_cpu_var(idt_desc) = *desc;
403 xen_convert_trap_info(desc, traps);
406 if (HYPERVISOR_set_trap_table(traps))
412 /* Write a GDT descriptor entry. Ignore LDT descriptors, since
413 they're handled differently. */
414 static void xen_write_gdt_entry(struct desc_struct *dt, int entry,
419 switch ((high >> 8) & 0xff) {
426 xmaddr_t maddr = virt_to_machine(&dt[entry]);
427 u64 desc = (u64)high << 32 | low;
430 if (HYPERVISOR_update_descriptor(maddr.maddr, desc))
439 static void xen_load_esp0(struct tss_struct *tss,
440 struct thread_struct *thread)
442 struct multicall_space mcs = xen_mc_entry(0);
443 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->esp0);
444 xen_mc_issue(PARAVIRT_LAZY_CPU);
447 static void xen_set_iopl_mask(unsigned mask)
449 struct physdev_set_iopl set_iopl;
451 /* Force the change at ring 0. */
452 set_iopl.iopl = (mask == 0) ? 1 : (mask >> 12) & 3;
453 HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl);
456 static void xen_io_delay(void)
460 #ifdef CONFIG_X86_LOCAL_APIC
461 static unsigned long xen_apic_read(unsigned long reg)
466 static void xen_apic_write(unsigned long reg, unsigned long val)
468 /* Warn to see if there's any stray references */
473 static void xen_flush_tlb(void)
477 op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
478 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
482 static void xen_flush_tlb_single(unsigned long addr)
486 op.cmd = MMUEXT_INVLPG_LOCAL;
487 op.arg1.linear_addr = addr & PAGE_MASK;
488 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
492 static void xen_flush_tlb_others(const cpumask_t *cpus, struct mm_struct *mm,
496 cpumask_t cpumask = *cpus;
499 * A couple of (to be removed) sanity checks:
501 * - current CPU must not be in mask
502 * - mask must exist :)
504 BUG_ON(cpus_empty(cpumask));
505 BUG_ON(cpu_isset(smp_processor_id(), cpumask));
508 /* If a CPU which we ran on has gone down, OK. */
509 cpus_and(cpumask, cpumask, cpu_online_map);
510 if (cpus_empty(cpumask))
513 if (va == TLB_FLUSH_ALL) {
514 op.cmd = MMUEXT_TLB_FLUSH_MULTI;
515 op.arg2.vcpumask = (void *)cpus;
517 op.cmd = MMUEXT_INVLPG_MULTI;
518 op.arg1.linear_addr = va;
519 op.arg2.vcpumask = (void *)cpus;
522 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
526 static unsigned long xen_read_cr2(void)
528 return x86_read_percpu(xen_vcpu)->arch.cr2;
531 static void xen_write_cr4(unsigned long cr4)
533 /* never allow TSC to be disabled */
534 native_write_cr4(cr4 & ~X86_CR4_TSD);
537 static unsigned long xen_read_cr3(void)
539 return x86_read_percpu(xen_cr3);
542 static void xen_write_cr3(unsigned long cr3)
544 BUG_ON(preemptible());
546 if (cr3 == x86_read_percpu(xen_cr3)) {
547 /* just a simple tlb flush */
552 x86_write_percpu(xen_cr3, cr3);
556 struct mmuext_op *op;
557 struct multicall_space mcs = xen_mc_entry(sizeof(*op));
558 unsigned long mfn = pfn_to_mfn(PFN_DOWN(cr3));
561 op->cmd = MMUEXT_NEW_BASEPTR;
564 MULTI_mmuext_op(mcs.mc, op, 1, NULL, DOMID_SELF);
566 xen_mc_issue(PARAVIRT_LAZY_CPU);
570 /* Early in boot, while setting up the initial pagetable, assume
571 everything is pinned. */
572 static __init void xen_alloc_pt_init(struct mm_struct *mm, u32 pfn)
574 BUG_ON(mem_map); /* should only be used early */
575 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
578 /* This needs to make sure the new pte page is pinned iff its being
579 attached to a pinned pagetable. */
580 static void xen_alloc_pt(struct mm_struct *mm, u32 pfn)
582 struct page *page = pfn_to_page(pfn);
584 if (PagePinned(virt_to_page(mm->pgd))) {
587 if (!PageHighMem(page))
588 make_lowmem_page_readonly(__va(PFN_PHYS(pfn)));
590 /* make sure there are no stray mappings of
596 /* This should never happen until we're OK to use struct page */
597 static void xen_release_pt(u32 pfn)
599 struct page *page = pfn_to_page(pfn);
601 if (PagePinned(page)) {
602 if (!PageHighMem(page))
603 make_lowmem_page_readwrite(__va(PFN_PHYS(pfn)));
607 #ifdef CONFIG_HIGHPTE
608 static void *xen_kmap_atomic_pte(struct page *page, enum km_type type)
610 pgprot_t prot = PAGE_KERNEL;
612 if (PagePinned(page))
613 prot = PAGE_KERNEL_RO;
615 if (0 && PageHighMem(page))
616 printk("mapping highpte %lx type %d prot %s\n",
617 page_to_pfn(page), type,
618 (unsigned long)pgprot_val(prot) & _PAGE_RW ? "WRITE" : "READ");
620 return kmap_atomic_prot(page, type, prot);
624 static __init pte_t mask_rw_pte(pte_t *ptep, pte_t pte)
626 /* If there's an existing pte, then don't allow _PAGE_RW to be set */
627 if (pte_val_ma(*ptep) & _PAGE_PRESENT)
628 pte = __pte_ma(((pte_val_ma(*ptep) & _PAGE_RW) | ~_PAGE_RW) &
634 /* Init-time set_pte while constructing initial pagetables, which
635 doesn't allow RO pagetable pages to be remapped RW */
636 static __init void xen_set_pte_init(pte_t *ptep, pte_t pte)
638 pte = mask_rw_pte(ptep, pte);
640 xen_set_pte(ptep, pte);
643 static __init void xen_pagetable_setup_start(pgd_t *base)
645 pgd_t *xen_pgd = (pgd_t *)xen_start_info->pt_base;
647 /* special set_pte for pagetable initialization */
648 paravirt_ops.set_pte = xen_set_pte_init;
652 * copy top-level of Xen-supplied pagetable into place. For
653 * !PAE we can use this as-is, but for PAE it is a stand-in
654 * while we copy the pmd pages.
656 memcpy(base, xen_pgd, PTRS_PER_PGD * sizeof(pgd_t));
658 if (PTRS_PER_PMD > 1) {
661 * For PAE, need to allocate new pmds, rather than
662 * share Xen's, since Xen doesn't like pmd's being
663 * shared between address spaces.
665 for (i = 0; i < PTRS_PER_PGD; i++) {
666 if (pgd_val_ma(xen_pgd[i]) & _PAGE_PRESENT) {
667 pmd_t *pmd = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
669 memcpy(pmd, (void *)pgd_page_vaddr(xen_pgd[i]),
672 make_lowmem_page_readonly(pmd);
674 set_pgd(&base[i], __pgd(1 + __pa(pmd)));
680 /* make sure zero_page is mapped RO so we can use it in pagetables */
681 make_lowmem_page_readonly(empty_zero_page);
682 make_lowmem_page_readonly(base);
684 * Switch to new pagetable. This is done before
685 * pagetable_init has done anything so that the new pages
686 * added to the table can be prepared properly for Xen.
688 xen_write_cr3(__pa(base));
691 static __init void xen_pagetable_setup_done(pgd_t *base)
693 /* This will work as long as patching hasn't happened yet
695 paravirt_ops.alloc_pt = xen_alloc_pt;
696 paravirt_ops.set_pte = xen_set_pte;
698 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
700 * Create a mapping for the shared info page.
701 * Should be set_fixmap(), but shared_info is a machine
702 * address with no corresponding pseudo-phys address.
704 set_pte_mfn(fix_to_virt(FIX_PARAVIRT_BOOTMAP),
705 PFN_DOWN(xen_start_info->shared_info),
708 HYPERVISOR_shared_info =
709 (struct shared_info *)fix_to_virt(FIX_PARAVIRT_BOOTMAP);
712 HYPERVISOR_shared_info =
713 (struct shared_info *)__va(xen_start_info->shared_info);
715 /* Actually pin the pagetable down, but we can't set PG_pinned
716 yet because the page structures don't exist yet. */
719 #ifdef CONFIG_X86_PAE
720 op.cmd = MMUEXT_PIN_L3_TABLE;
722 op.cmd = MMUEXT_PIN_L3_TABLE;
724 op.arg1.mfn = pfn_to_mfn(PFN_DOWN(__pa(base)));
725 if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF))
729 xen_vcpu_setup(smp_processor_id());
732 static const struct paravirt_ops xen_paravirt_ops __initdata = {
733 .paravirt_enabled = 1,
734 .shared_kernel_pmd = 0,
737 .banner = xen_banner,
739 .patch = paravirt_patch_default,
741 .memory_setup = xen_memory_setup,
742 .arch_setup = xen_arch_setup,
743 .init_IRQ = xen_init_IRQ,
744 .post_allocator_init = xen_mark_init_mm_pinned,
746 .time_init = xen_time_init,
747 .set_wallclock = xen_set_wallclock,
748 .get_wallclock = xen_get_wallclock,
749 .get_cpu_khz = xen_cpu_khz,
750 .sched_clock = xen_sched_clock,
754 .set_debugreg = xen_set_debugreg,
755 .get_debugreg = xen_get_debugreg,
759 .read_cr0 = native_read_cr0,
760 .write_cr0 = native_write_cr0,
762 .read_cr2 = xen_read_cr2,
763 .write_cr2 = native_write_cr2,
765 .read_cr3 = xen_read_cr3,
766 .write_cr3 = xen_write_cr3,
768 .read_cr4 = native_read_cr4,
769 .read_cr4_safe = native_read_cr4_safe,
770 .write_cr4 = xen_write_cr4,
772 .save_fl = xen_save_fl,
773 .restore_fl = xen_restore_fl,
774 .irq_disable = xen_irq_disable,
775 .irq_enable = xen_irq_enable,
776 .safe_halt = xen_safe_halt,
778 .wbinvd = native_wbinvd,
780 .read_msr = native_read_msr_safe,
781 .write_msr = native_write_msr_safe,
782 .read_tsc = native_read_tsc,
783 .read_pmc = native_read_pmc,
785 .iret = (void *)&hypercall_page[__HYPERVISOR_iret],
786 .irq_enable_sysexit = NULL, /* never called */
788 .load_tr_desc = paravirt_nop,
789 .set_ldt = xen_set_ldt,
790 .load_gdt = xen_load_gdt,
791 .load_idt = xen_load_idt,
792 .load_tls = xen_load_tls,
794 .store_gdt = native_store_gdt,
795 .store_idt = native_store_idt,
796 .store_tr = xen_store_tr,
798 .write_ldt_entry = xen_write_ldt_entry,
799 .write_gdt_entry = xen_write_gdt_entry,
800 .write_idt_entry = xen_write_idt_entry,
801 .load_esp0 = xen_load_esp0,
803 .set_iopl_mask = xen_set_iopl_mask,
804 .io_delay = xen_io_delay,
806 #ifdef CONFIG_X86_LOCAL_APIC
807 .apic_write = xen_apic_write,
808 .apic_write_atomic = xen_apic_write,
809 .apic_read = xen_apic_read,
810 .setup_boot_clock = paravirt_nop,
811 .setup_secondary_clock = paravirt_nop,
812 .startup_ipi_hook = paravirt_nop,
815 .flush_tlb_user = xen_flush_tlb,
816 .flush_tlb_kernel = xen_flush_tlb,
817 .flush_tlb_single = xen_flush_tlb_single,
818 .flush_tlb_others = xen_flush_tlb_others,
820 .pte_update = paravirt_nop,
821 .pte_update_defer = paravirt_nop,
823 .pagetable_setup_start = xen_pagetable_setup_start,
824 .pagetable_setup_done = xen_pagetable_setup_done,
826 .alloc_pt = xen_alloc_pt_init,
827 .release_pt = xen_release_pt,
828 .alloc_pd = paravirt_nop,
829 .alloc_pd_clone = paravirt_nop,
830 .release_pd = paravirt_nop,
832 #ifdef CONFIG_HIGHPTE
833 .kmap_atomic_pte = xen_kmap_atomic_pte,
836 .set_pte = NULL, /* see xen_pagetable_setup_* */
837 .set_pte_at = xen_set_pte_at,
838 .set_pmd = xen_set_pmd,
840 .pte_val = xen_pte_val,
841 .pgd_val = xen_pgd_val,
843 .make_pte = xen_make_pte,
844 .make_pgd = xen_make_pgd,
846 #ifdef CONFIG_X86_PAE
847 .set_pte_atomic = xen_set_pte_atomic,
848 .set_pte_present = xen_set_pte_at,
849 .set_pud = xen_set_pud,
850 .pte_clear = xen_pte_clear,
851 .pmd_clear = xen_pmd_clear,
853 .make_pmd = xen_make_pmd,
854 .pmd_val = xen_pmd_val,
857 .activate_mm = xen_activate_mm,
858 .dup_mmap = xen_dup_mmap,
859 .exit_mmap = xen_exit_mmap,
861 .set_lazy_mode = xen_set_lazy_mode,
865 static const struct smp_ops xen_smp_ops __initdata = {
866 .smp_prepare_boot_cpu = xen_smp_prepare_boot_cpu,
867 .smp_prepare_cpus = xen_smp_prepare_cpus,
868 .cpu_up = xen_cpu_up,
869 .smp_cpus_done = xen_smp_cpus_done,
871 .smp_send_stop = xen_smp_send_stop,
872 .smp_send_reschedule = xen_smp_send_reschedule,
873 .smp_call_function_mask = xen_smp_call_function_mask,
875 #endif /* CONFIG_SMP */
877 /* First C function to be called on Xen boot */
878 asmlinkage void __init xen_start_kernel(void)
885 BUG_ON(memcmp(xen_start_info->magic, "xen-3.0", 7) != 0);
887 /* Install Xen paravirt ops */
888 paravirt_ops = xen_paravirt_ops;
890 smp_ops = xen_smp_ops;
893 xen_setup_features();
896 if (!xen_feature(XENFEAT_auto_translated_physmap))
897 phys_to_machine_mapping = (unsigned long *)xen_start_info->mfn_list;
899 pgd = (pgd_t *)xen_start_info->pt_base;
901 init_pg_tables_end = __pa(pgd) + xen_start_info->nr_pt_frames*PAGE_SIZE;
903 init_mm.pgd = pgd; /* use the Xen pagetables to start */
905 /* keep using Xen gdt for now; no urgent need to change it */
907 x86_write_percpu(xen_cr3, __pa(pgd));
910 paravirt_ops.kernel_rpl = 1;
911 if (xen_feature(XENFEAT_supervisor_mode_kernel))
912 paravirt_ops.kernel_rpl = 0;
914 /* set the limit of our address space */
915 reserve_top_address(-HYPERVISOR_VIRT_START + 2 * PAGE_SIZE);
917 /* set up basic CPUID stuff */
918 cpu_detect(&new_cpu_data);
919 new_cpu_data.hard_math = 1;
920 new_cpu_data.x86_capability[0] = cpuid_edx(1);
922 /* Poke various useful things into boot_params */
923 LOADER_TYPE = (9 << 4) | 0;
924 INITRD_START = xen_start_info->mod_start ? __pa(xen_start_info->mod_start) : 0;
925 INITRD_SIZE = xen_start_info->mod_len;
927 /* Start the world */