diff --git a/sys/x86/include/xen/xen-os.h b/sys/x86/include/xen/xen-os.h --- a/sys/x86/include/xen/xen-os.h +++ b/sys/x86/include/xen/xen-os.h @@ -52,8 +52,6 @@ /* tunable for disabling PV nics */ extern int xen_disable_pv_nics; -extern uint32_t xen_cpuid_base; - /* compatibility for accessing xen_ulong_t with atomics */ #define atomic_clear_xen_ulong atomic_clear_long #define atomic_set_xen_ulong atomic_set_long diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c --- a/sys/x86/x86/identcpu.c +++ b/sys/x86/x86/identcpu.c @@ -67,6 +67,8 @@ #include #include +#include + #ifdef __i386__ #define IDENTBLUE_CYRIX486 0 #define IDENTBLUE_IBMCPU 1 @@ -1345,7 +1347,11 @@ int vm_guest; void (*init)(void); } vm_cpuids[] = { - { "XenVMMXenVMM", VM_GUEST_XEN }, /* XEN */ + { "XenVMMXenVMM", VM_GUEST_XEN, +#ifdef XENHVM + &xen_early_init, +#endif + }, /* XEN */ { "Microsoft Hv", VM_GUEST_HV }, /* Microsoft Hyper-V */ { "VMwareVMware", VM_GUEST_VMWARE }, /* VMware VM */ { "KVMKVMKVM", VM_GUEST_KVM }, /* KVM */ diff --git a/sys/x86/xen/hvm.c b/sys/x86/xen/hvm.c --- a/sys/x86/xen/hvm.c +++ b/sys/x86/xen/hvm.c @@ -104,22 +104,6 @@ outsb(XEN_HVM_DEBUGCONS_IOPORT, str, size); } -uint32_t xen_cpuid_base; - -static uint32_t -xen_hvm_cpuid_base(void) -{ - uint32_t base, regs[4]; - - for (base = 0x40000000; base < 0x40010000; base += 0x100) { - do_cpuid(base, regs); - if (!memcmp("XenVMMXenVMM", ®s[1], 12) - && (regs[0] - base) >= 2) - return (base); - } - return (0); -} - static void hypervisor_quirks(unsigned int major, unsigned int minor) { @@ -156,38 +140,6 @@ hypervisor_quirks(major, minor); } -/* - * Allocate and fill in the hypcall page. - */ -int -xen_hvm_init_hypercall_stubs(enum xen_hvm_init_type init_type) -{ - uint32_t regs[4]; - - if (xen_cpuid_base != 0) - /* Already setup. */ - goto out; - - xen_cpuid_base = xen_hvm_cpuid_base(); - if (xen_cpuid_base == 0) - return (ENXIO); - - /* - * Find the hypercall pages. - */ - do_cpuid(xen_cpuid_base + 2, regs); - if (regs[0] != 1) - return (EINVAL); - - wrmsr(regs[1], (init_type == XEN_HVM_INIT_EARLY) - ? (vm_paddr_t)((uintptr_t)&hypercall_page - KERNBASE) - : vtophys(&hypercall_page)); - -out: - hypervisor_version(); - return (0); -} - /* * Translate linear to physical address when still running on the bootloader * created page-tables. @@ -326,12 +278,14 @@ uint32_t regs[4]; int rc; - xen_cpuid_base = xen_hvm_cpuid_base(); - if ( xen_cpuid_base == 0 ) + if (hv_high < 2) { + xc_printf("Invalid maximum leaves for hv_base\n"); + vm_guest = VM_GUEST_VM; return; + } /* Find the hypercall pages. */ - do_cpuid(xen_cpuid_base + 2, regs); + do_cpuid(hv_base + 2, regs); if (regs[0] != 1) { xc_printf("Invalid number of hypercall pages %" PRIu32 "\n", regs[0]); @@ -348,35 +302,9 @@ return; } - /* Fixup video console information in case Xen has changed the mode. */ - fixup_console(); -} - -static void -xen_hvm_init_shared_info_page(void) -{ - struct xen_add_to_physmap xatp; - - if (xen_pv_domain()) { - /* - * Already setup in the PV case, shared_info is passed inside - * of the start_info struct at start of day. - */ - return; - } - - if (HYPERVISOR_shared_info == NULL) { - HYPERVISOR_shared_info = malloc(PAGE_SIZE, M_XENHVM, M_NOWAIT); - if (HYPERVISOR_shared_info == NULL) - panic("Unable to allocate Xen shared info page"); - } - - xatp.domid = DOMID_SELF; - xatp.idx = 0; - xatp.space = XENMAPSPACE_shared_info; - xatp.gpfn = vtophys(HYPERVISOR_shared_info) >> PAGE_SHIFT; - if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp)) - panic("HYPERVISOR_memory_op failed"); + if (xen_initial_domain()) + /* Fixup video console information in case Xen changed it. */ + fixup_console(); } static int @@ -495,32 +423,29 @@ static void xen_hvm_init(enum xen_hvm_init_type init_type) { - int error; - int i; + unsigned int i; if (!xen_domain() || init_type == XEN_HVM_INIT_CANCELLED_SUSPEND) return; - error = xen_hvm_init_hypercall_stubs(init_type); + hypervisor_version(); switch (init_type) { case XEN_HVM_INIT_LATE: - if (error != 0) - return; - setup_xen_features(); #ifdef SMP cpu_ops = xen_hvm_cpu_ops; #endif break; case XEN_HVM_INIT_RESUME: - if (error != 0) - panic("Unable to init Xen hypercall stubs on resume"); - /* Clear stale vcpu_info. */ CPU_FOREACH(i) DPCPU_ID_SET(i, vcpu_info, NULL); + + if (map_shared_info() != 0) + panic("cannot map shared info page\n"); + break; default: panic("Unsupported HVM initialization type"); @@ -530,13 +455,6 @@ xen_evtchn_needs_ack = false; xen_hvm_set_callback(NULL); - /* - * On (PV)HVM domains we need to request the hypervisor to - * fill the shared info page, for PVH guest the shared_info page - * is passed inside the start_info struct and is already set, so this - * functions are no-ops. - */ - xen_hvm_init_shared_info_page(); xen_hvm_disable_emulated_devices(); } diff --git a/sys/x86/xen/pv.c b/sys/x86/xen/pv.c --- a/sys/x86/xen/pv.c +++ b/sys/x86/xen/pv.c @@ -147,12 +147,9 @@ } #define CRASH(...) do { \ - if (isxen()) { \ + if (isxen()) \ xc_printf(__VA_ARGS__); \ - HYPERVISOR_shutdown(SHUTDOWN_crash); \ - } else { \ - halt(); \ - } \ + halt(); \ } while (0) uint64_t @@ -162,16 +159,6 @@ uint64_t physfree; char *kenv; - if (isxen()) { - vm_guest = VM_GUEST_XEN; - xen_early_init(); - if (xen_cpuid_base == 0) { - xc_printf( - "ERROR: failed to initialize hypercall page\n"); - HYPERVISOR_shutdown(SHUTDOWN_crash); - } - } - start_info = (struct hvm_start_info *)(start_info_paddr + KERNBASE); if (start_info->magic != XEN_HVM_START_MAGIC_VALUE) { CRASH("Unknown magic value in start_info struct: %#x\n",