enlighten.c (bf992fa2bc1ad1bb2aeb0bdfadb43f236b9297fd) enlighten.c (577eebeae34d340685d8985dfdb7dfe337c511e8)
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

--- 37 unchanged lines hidden (view full) ---

46#include <asm/proto.h>
47#include <asm/msr-index.h>
48#include <asm/traps.h>
49#include <asm/setup.h>
50#include <asm/desc.h>
51#include <asm/pgtable.h>
52#include <asm/tlbflush.h>
53#include <asm/reboot.h>
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

--- 37 unchanged lines hidden (view full) ---

46#include <asm/proto.h>
47#include <asm/msr-index.h>
48#include <asm/traps.h>
49#include <asm/setup.h>
50#include <asm/desc.h>
51#include <asm/pgtable.h>
52#include <asm/tlbflush.h>
53#include <asm/reboot.h>
54#include <asm/stackprotector.h>
54
55#include "xen-ops.h"
56#include "mmu.h"
57#include "multicalls.h"
58
59EXPORT_SYMBOL_GPL(hypercall_page);
60
61DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);

--- 263 unchanged lines hidden (view full) ---

325static void xen_load_gdt(const struct desc_ptr *dtr)
326{
327 unsigned long va = dtr->address;
328 unsigned int size = dtr->size + 1;
329 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
330 unsigned long frames[pages];
331 int f;
332
55
56#include "xen-ops.h"
57#include "mmu.h"
58#include "multicalls.h"
59
60EXPORT_SYMBOL_GPL(hypercall_page);
61
62DEFINE_PER_CPU(struct vcpu_info *, xen_vcpu);

--- 263 unchanged lines hidden (view full) ---

326static void xen_load_gdt(const struct desc_ptr *dtr)
327{
328 unsigned long va = dtr->address;
329 unsigned int size = dtr->size + 1;
330 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
331 unsigned long frames[pages];
332 int f;
333
333 /* A GDT can be up to 64k in size, which corresponds to 8192
334 8-byte entries, or 16 4k pages.. */
334 /*
335 * A GDT can be up to 64k in size, which corresponds to 8192
336 * 8-byte entries, or 16 4k pages..
337 */
335
336 BUG_ON(size > 65536);
337 BUG_ON(va & ~PAGE_MASK);
338
339 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
340 int level;
338
339 BUG_ON(size > 65536);
340 BUG_ON(va & ~PAGE_MASK);
341
342 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
343 int level;
341 pte_t *ptep = lookup_address(va, &level);
344 pte_t *ptep;
342 unsigned long pfn, mfn;
343 void *virt;
344
345 unsigned long pfn, mfn;
346 void *virt;
347
348 /*
349 * The GDT is per-cpu and is in the percpu data area.
350 * That can be virtually mapped, so we need to do a
351 * page-walk to get the underlying MFN for the
352 * hypercall. The page can also be in the kernel's
353 * linear range, so we need to RO that mapping too.
354 */
355 ptep = lookup_address(va, &level);
345 BUG_ON(ptep == NULL);
346
347 pfn = pte_pfn(*ptep);
348 mfn = pfn_to_mfn(pfn);
349 virt = __va(PFN_PHYS(pfn));
350
351 frames[f] = mfn;
352
353 make_lowmem_page_readonly((void *)va);
354 make_lowmem_page_readonly(virt);
355 }
356
357 if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
358 BUG();
359}
360
356 BUG_ON(ptep == NULL);
357
358 pfn = pte_pfn(*ptep);
359 mfn = pfn_to_mfn(pfn);
360 virt = __va(PFN_PHYS(pfn));
361
362 frames[f] = mfn;
363
364 make_lowmem_page_readonly((void *)va);
365 make_lowmem_page_readonly(virt);
366 }
367
368 if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
369 BUG();
370}
371
372/*
373 * load_gdt for early boot, when the gdt is only mapped once
374 */
375static __init void xen_load_gdt_boot(const struct desc_ptr *dtr)
376{
377 unsigned long va = dtr->address;
378 unsigned int size = dtr->size + 1;
379 unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
380 unsigned long frames[pages];
381 int f;
382
383 /*
384 * A GDT can be up to 64k in size, which corresponds to 8192
385 * 8-byte entries, or 16 4k pages..
386 */
387
388 BUG_ON(size > 65536);
389 BUG_ON(va & ~PAGE_MASK);
390
391 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
392 pte_t pte;
393 unsigned long pfn, mfn;
394
395 pfn = virt_to_pfn(va);
396 mfn = pfn_to_mfn(pfn);
397
398 pte = pfn_pte(pfn, PAGE_KERNEL_RO);
399
400 if (HYPERVISOR_update_va_mapping((unsigned long)va, pte, 0))
401 BUG();
402
403 frames[f] = mfn;
404 }
405
406 if (HYPERVISOR_set_gdt(frames, size / sizeof(struct desc_struct)))
407 BUG();
408}
409
361static void load_TLS_descriptor(struct thread_struct *t,
362 unsigned int cpu, unsigned int i)
363{
364 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
365 xmaddr_t maddr = arbitrary_virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
366 struct multicall_space mc = __xen_mc_entry(0);
367
368 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);

--- 207 unchanged lines hidden (view full) ---

576 BUG();
577 }
578
579 }
580
581 preempt_enable();
582}
583
410static void load_TLS_descriptor(struct thread_struct *t,
411 unsigned int cpu, unsigned int i)
412{
413 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
414 xmaddr_t maddr = arbitrary_virt_to_machine(&gdt[GDT_ENTRY_TLS_MIN+i]);
415 struct multicall_space mc = __xen_mc_entry(0);
416
417 MULTI_update_descriptor(mc.mc, maddr.maddr, t->tls_array[i]);

--- 207 unchanged lines hidden (view full) ---

625 BUG();
626 }
627
628 }
629
630 preempt_enable();
631}
632
633/*
634 * Version of write_gdt_entry for use at early boot-time needed to
635 * update an entry as simply as possible.
636 */
637static __init void xen_write_gdt_entry_boot(struct desc_struct *dt, int entry,
638 const void *desc, int type)
639{
640 switch (type) {
641 case DESC_LDT:
642 case DESC_TSS:
643 /* ignore */
644 break;
645
646 default: {
647 xmaddr_t maddr = virt_to_machine(&dt[entry]);
648
649 if (HYPERVISOR_update_descriptor(maddr.maddr, *(u64 *)desc))
650 dt[entry] = *(struct desc_struct *)desc;
651 }
652
653 }
654}
655
584static void xen_load_sp0(struct tss_struct *tss,
585 struct thread_struct *thread)
586{
587 struct multicall_space mcs = xen_mc_entry(0);
588 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->sp0);
589 xen_mc_issue(PARAVIRT_LAZY_CPU);
590}
591

--- 368 unchanged lines hidden (view full) ---

960 .restart = xen_restart,
961 .halt = xen_machine_halt,
962 .power_off = xen_machine_halt,
963 .shutdown = xen_machine_halt,
964 .crash_shutdown = xen_crash_shutdown,
965 .emergency_restart = xen_emergency_restart,
966};
967
656static void xen_load_sp0(struct tss_struct *tss,
657 struct thread_struct *thread)
658{
659 struct multicall_space mcs = xen_mc_entry(0);
660 MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->sp0);
661 xen_mc_issue(PARAVIRT_LAZY_CPU);
662}
663

--- 368 unchanged lines hidden (view full) ---

1032 .restart = xen_restart,
1033 .halt = xen_machine_halt,
1034 .power_off = xen_machine_halt,
1035 .shutdown = xen_machine_halt,
1036 .crash_shutdown = xen_crash_shutdown,
1037 .emergency_restart = xen_emergency_restart,
1038};
1039
1040/*
1041 * Set up the GDT and segment registers for -fstack-protector. Until
1042 * we do this, we have to be careful not to call any stack-protected
1043 * function, which is most of the kernel.
1044 */
1045static void __init xen_setup_stackprotector(void)
1046{
1047 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
1048 pv_cpu_ops.load_gdt = xen_load_gdt_boot;
1049
1050 setup_stack_canary_segment(0);
1051 switch_to_new_gdt(0);
1052
1053 pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
1054 pv_cpu_ops.load_gdt = xen_load_gdt;
1055}
1056
968/* First C function to be called on Xen boot */
969asmlinkage void __init xen_start_kernel(void)
970{
971 pgd_t *pgd;
972
973 if (!xen_start_info)
974 return;
975
976 xen_domain_type = XEN_PV_DOMAIN;
977
978 /* Install Xen paravirt ops */
979 pv_info = xen_info;
980 pv_init_ops = xen_init_ops;
981 pv_time_ops = xen_time_ops;
982 pv_cpu_ops = xen_cpu_ops;
983 pv_apic_ops = xen_apic_ops;
984 pv_mmu_ops = xen_mmu_ops;
985
1057/* First C function to be called on Xen boot */
1058asmlinkage void __init xen_start_kernel(void)
1059{
1060 pgd_t *pgd;
1061
1062 if (!xen_start_info)
1063 return;
1064
1065 xen_domain_type = XEN_PV_DOMAIN;
1066
1067 /* Install Xen paravirt ops */
1068 pv_info = xen_info;
1069 pv_init_ops = xen_init_ops;
1070 pv_time_ops = xen_time_ops;
1071 pv_cpu_ops = xen_cpu_ops;
1072 pv_apic_ops = xen_apic_ops;
1073 pv_mmu_ops = xen_mmu_ops;
1074
986#ifdef CONFIG_X86_64
987 /*
1075 /*
988 * Setup percpu state. We only need to do this for 64-bit
989 * because 32-bit already has %fs set properly.
1076 * Set up some pagetable state before starting to set any ptes.
990 */
1077 */
991 load_percpu_segment(0);
992#endif
993
1078
1079 /* Prevent unwanted bits from being set in PTEs. */
1080 __supported_pte_mask &= ~_PAGE_GLOBAL;
1081 if (!xen_initial_domain())
1082 __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
1083
1084 __supported_pte_mask |= _PAGE_IOMAP;
1085
1086 xen_setup_features();
1087
1088 /* Get mfn list */
1089 if (!xen_feature(XENFEAT_auto_translated_physmap))
1090 xen_build_dynamic_phys_to_machine();
1091
1092 /*
1093 * Set up kernel GDT and segment registers, mainly so that
1094 * -fstack-protector code can be executed.
1095 */
1096 xen_setup_stackprotector();
1097
994 xen_init_irq_ops();
995 xen_init_cpuid_mask();
996
997#ifdef CONFIG_X86_LOCAL_APIC
998 /*
999 * set up the basic apic ops.
1000 */
1001 set_xen_basic_apic_ops();
1002#endif
1003
1098 xen_init_irq_ops();
1099 xen_init_cpuid_mask();
1100
1101#ifdef CONFIG_X86_LOCAL_APIC
1102 /*
1103 * set up the basic apic ops.
1104 */
1105 set_xen_basic_apic_ops();
1106#endif
1107
1004 xen_setup_features();
1005
1006 if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
1007 pv_mmu_ops.ptep_modify_prot_start = xen_ptep_modify_prot_start;
1008 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
1009 }
1010
1011 machine_ops = xen_machine_ops;
1012
1013 /*
1014 * The only reliable way to retain the initial address of the
1015 * percpu gdt_page is to remember it here, so we can go and
1016 * mark it RW later, when the initial percpu area is freed.
1017 */
1018 xen_initial_gdt = &per_cpu(gdt_page, 0);
1019
1020 xen_smp_init();
1021
1108 if (xen_feature(XENFEAT_mmu_pt_update_preserve_ad)) {
1109 pv_mmu_ops.ptep_modify_prot_start = xen_ptep_modify_prot_start;
1110 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
1111 }
1112
1113 machine_ops = xen_machine_ops;
1114
1115 /*
1116 * The only reliable way to retain the initial address of the
1117 * percpu gdt_page is to remember it here, so we can go and
1118 * mark it RW later, when the initial percpu area is freed.
1119 */
1120 xen_initial_gdt = &per_cpu(gdt_page, 0);
1121
1122 xen_smp_init();
1123
1022 /* Get mfn list */
1023 if (!xen_feature(XENFEAT_auto_translated_physmap))
1024 xen_build_dynamic_phys_to_machine();
1025
1026 pgd = (pgd_t *)xen_start_info->pt_base;
1027
1124 pgd = (pgd_t *)xen_start_info->pt_base;
1125
1028 /* Prevent unwanted bits from being set in PTEs. */
1029 __supported_pte_mask &= ~_PAGE_GLOBAL;
1030 if (!xen_initial_domain())
1031 __supported_pte_mask &= ~(_PAGE_PWT | _PAGE_PCD);
1032
1033#ifdef CONFIG_X86_64
1034 /* Work out if we support NX */
1035 check_efer();
1036#endif
1037
1038 /* Don't do the full vcpu_info placement stuff until we have a
1039 possible map and a non-dummy shared_info. */
1040 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];

--- 48 unchanged lines hidden ---
1126#ifdef CONFIG_X86_64
1127 /* Work out if we support NX */
1128 check_efer();
1129#endif
1130
1131 /* Don't do the full vcpu_info placement stuff until we have a
1132 possible map and a non-dummy shared_info. */
1133 per_cpu(xen_vcpu, 0) = &HYPERVISOR_shared_info->vcpu_info[0];

--- 48 unchanged lines hidden ---