mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
This changeset contains all differences between xen-unstable.hg and xen-unstable-hvm.hg. All information and comments for changesets unique to xen-unstable-hvm.hg are included below. Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> Signed-off-by: Keir Fraser <keir@xensource.com> > user: leendert@eserver2.watson.ibm.com > date: Tue Jan 31 04:29:51 2006 -0400 > files: xen/include/asm-ia64/mm.h > description: > Fix ia64 compile. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Tue Jan 31 02:21:49 2006 -0400 > files: xen/include/xen/domain_page.h > description: > Eliminate unused fields (pfn,va) warnings. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Fri Jan 27 04:31:44 2006 -0400 > files: tools/python/xen/xend/image.py > description: > Name cleanup. vmx refers to VT-x specific code, HVM is used for all others. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: root@xen-trw1.amd.com > date: Sun Jan 22 18:39:58 2006 -0500 > files: xen/arch/x86/hvm/platform.c > description: > support prefix 0x67 in hvm decode logic, gfxboot patch causes 0x67 prefix. > > > user: twoller@xen-trw1.amd.com > date: Sun Jan 22 18:35:59 2006 -0500 > files: xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/vmcb.c xen/include/asm-x86/hvm/svm/svm.h > description: > check for valid shared_page_va/vmcb before deallocating in SVM. > > > user: leendert@eserver2.watson.ibm.com > date: Sun Jan 22 02:56:20 2006 -0400 > files: xen/include/asm-x86/hvm/svm/svm.h xen/include/asm-x86/hvm/svm/vmmcall.h > description: > Some SVM header file cleanups. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Fri Jan 20 11:50:23 2006 -0400 > files: xen/arch/x86/domain.c > description: > Need to be more diligent about when to call into the HVM abstraction layer > and when not. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Wed Jan 18 15:14:56 2006 -0400 > files: xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/x86_32/exits.S xen/arch/x86/hvm/svm/x86_64/exits.S xen/arch/x86/hvm/vmx/x86_32/exits.S xen/arch/x86/hvm/vmx/x86_64/exits.S > description: > Added missing copyright statements and updated svm.c's copyright to properly > reflect that it was derived from vmx.c. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Tue Jan 17 09:42:11 2006 -0400 > files: xen/arch/ia64/Makefile xen/arch/ia64/vmx/vlsapic.c xen/arch/ia64/vmx/vmx_init.c xen/include/asm-ia64/vmx_platform.h > description: > Make sure ia64 builds again with the new directory structure. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@localhost.localdomain > date: Tue Jan 17 08:28:51 2006 -0400 > files: xen/arch/x86/Makefile xen/arch/x86/hvm/i8259.c xen/arch/x86/hvm/vioapic.c > description: > The device models now belong in hvm. > > Signed-ff-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sun Jan 15 16:40:58 2006 -0400 > files: xen/arch/x86/Makefile xen/arch/x86/cpu/amd.c xen/arch/x86/cpu/intel.c xen/arch/x86/dm/hvm_vioapic.c xen/arch/x86/dm/i8259.c xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/hvm/hvm.c xen/arch/x86/hvm/intercept.c xen/arch/x86/hvm/io.c xen/arch/x86/hvm/platform.c xen/arch/x86/hvm/svm/emulate.c xen/arch/x86/hvm/svm/instrlen.c xen/arch/x86/hvm/svm/intr.c xen/arch/x86/hvm/svm/svm.c xen/arch/x86/hvm/svm/vmcb.c xen/arch/x86/hvm/svm/x86_32/exits.S xen/arch/x86/hvm/svm/x86_64/exits.S xen/arch/x86/hvm/vlapic.c xen/arch/x86/hvm/vmx/io.c xen/arch/x86/hvm/vmx/vmcs.c xen/arch/x86/hvm/vmx/vmx.c xen/arch/x86/hvm/vmx/x86_32/exits.S xen/arch/x86/hvm/vmx/x86_64/exits.S xen/arch/x86/i387.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/traps.c xen/include/asm-x86/domain.h xen/include/asm-x86/hvm/domain.h xen/include/asm-x86/hvm/hvm.h xen/include/asm-x86/hvm/io.h xen/include/asm-x86/hvm/support.h xen/include/asm-x86/hvm/svm/emulate.h xen/include/asm-x86/hvm/svm/intr.h xen/include/asm-x86/hvm/svm/svm.h xen/include/asm-x86/hvm/svm/vmcb.h xen/include/asm-x86/hvm/svm/vmmcall.h xen/include/asm-x86/hvm/vcpu.h xen/include/asm-x86/hvm/vioapic.h xen/include/asm-x86/hvm/vlapic.h xen/include/asm-x86/hvm/vmx/cpu.h xen/include/asm-x86/hvm/vmx/vmcs.h xen/include/asm-x86/hvm/vmx/vmx.h xen/include/asm-x86/hvm/vpic.h xen/include/asm-x86/hvm/vpit.h xen/include/asm-x86/shadow.h > description: > As suggested by Keir, I restructured the hvm/vmx/svm tree. The new > directory structure looks like: > > xen/arch/hvm/ > xen/arch/hvm/vmx > xen/arch/hvm/vmx/x86_32 > xen/arch/hvm/vmx/x86_64 > xen/arch/hvm/svm > xen/arch/hvm/svm/x86_32 > xen/arch/hvm/svm/x86_64 > > xen/include/hvm/ > xen/include/hvm/vmx > xen/include/hvm/svm > > Many files have been renamed and had their hvm_/vmx_/svm_ suffix removed > because this is now clear from the directory where the file resides. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sat Jan 14 17:03:28 2006 -0400 > files: xen/arch/ia64/vmx/vlsapic.c xen/include/asm-ia64/vmx_platform.h > description: > Name change fix for ia64. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sat Jan 14 15:12:59 2006 -0400 > files: xen/arch/x86/dm/hvm_vioapic.c xen/arch/x86/dm/i8259.c xen/arch/x86/hvm.c xen/arch/x86/hvm_intercept.c xen/arch/x86/svm.c xen/arch/x86/svm_intr.c xen/arch/x86/svm_vmcb.c xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_vmcs.c xen/include/asm-x86/hvm_domain.h xen/include/asm-x86/hvm_vcpu.h > description: > Move VMX/SVM print buffer to hvm_domain. > > Cleanup variable names. The suffix hvm_ is redundant in hvm_domain. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: twoller@xen-trw1.site > date: Fri Jan 13 17:03:18 2006 -0500 > files: xen/arch/x86/svm.c > description: > remove unnecessary spin_unlock in asid_fetch code for svm. > > > user: twoller@xen-trw1.site > date: Wed Jan 11 20:00:36 2006 -0500 > files: xen/arch/x86/svm.c > description: > remove unneeded update_pagetables() during svm PF handling (resolved with ASID code rework). > > > user: leendert@eserver2.watson.ibm.com > date: Tue Jan 10 02:45:32 2006 -0400 > files: xen/arch/x86/hvm.c xen/arch/x86/vmx_io.c > description: > Factor out cpu_get_interrupt(). It is used by VMX and SVM. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Mon Jan 9 00:03:30 2006 -0400 > files: xen/arch/x86/hvm.c xen/arch/x86/svm.c xen/arch/x86/vmx.c xen/include/asm-x86/hvm_support.h xen/include/asm-x86/hvm_vcpu.h > description: > Introduce small print buffer per domain rather than a single global one. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sun Jan 8 23:07:12 2006 -0400 > files: xen/arch/x86/dom0_ops.c xen/include/asm-x86/hvm_support.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h > description: > More cleanup. There is no point in distinguishing between SVM and VMX, > a single HVM flag bit suffices. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sun Jan 8 12:05:59 2006 -0400 > files: xen/arch/x86/svm.c xen/arch/x86/vmx.c > description: > Both VMX & SVM now print writes to the debug port (0xE9) on the console. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Sat Jan 7 13:55:27 2006 -0400 > files: xen/arch/x86/svm.c xen/arch/x86/svm_intr.c xen/arch/x86/svm_vmcb.c xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_vmcs.c xen/arch/x86/x86_32/asm-offsets.c xen/arch/x86/x86_64/asm-offsets.c xen/include/asm-x86/domain.h xen/include/asm-x86/vmx.h > description: > Introduce shorthands to improve code legibility. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Wed Jan 4 06:12:10 2006 -0400 > files: tools/examples/xmexample.hvm > description: > Minor spelling mistakes. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Wed Jan 4 03:37:55 2006 -0400 > files: xen/include/public/hvm/hvm_info_table.h xen/include/public/hvm/ioreq.h xen/include/public/hvm/vmx_assist.h > description: > Missed adding new files. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Mon Jan 2 01:23:54 2006 -0400 > files: tools/debugger/libxendebug/xendebug.c tools/libxc/xc_hvm_build.c > description: > Finalize Xin Li's patch: vmx/svm_identify is no longer necessary. > Xen debug should test for HVM instead of VMX. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: twoller@xen-trw1.site > date: Sun Jan 1 03:22:39 2006 -0500 > files: tools/ioemu/vl.c > description: > change hardcoded VTXEN to HVMXEN. > > > user: leendert@eserver2.watson.ibm.com > date: Sun Jan 1 02:22:47 2006 -0400 > files: tools/libxc/xc_hvm_build.c tools/python/xen/xend/image.py xen/arch/x86/domain.c > description: > Avoid xen crash if there is no VMX support. If a platform > doesn't support VMX, creating VMX domain will crash xen > HV. > > Signed-off-by: Xin Li <xin.b.li@intel.com> > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > [ vmx/svm_identify are still needed in hvm builder, but this may not > really be necessary. I need to check this. - lvd ] > > > user: twoller@xen-trw1.site > date: Fri Dec 30 21:38:56 2005 -0500 > files: xen/arch/x86/svm.c xen/arch/x86/svm_vmcb.c xen/arch/x86/x86_32/entry.S xen/include/asm-x86/svm.h xen/include/asm-x86/svm_vmcb.h > description: > add multi-core support for guest ASIDs for SVM partitions. > > > user: leendert@eserver2.watson.ibm.com > date: Sun Dec 25 20:44:43 2005 -0400 > files: tools/firmware/vmxassist/head.S > description: > Make sure vmxassist still works in its debug environment. > > Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Fri Dec 23 18:27:57 2005 -0400 > files: tools/libxc/xc_ia64_stubs.c > description: > Fixed libxc ia64, xend uses xc_hvm_build instead of xc_vmx_build. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: twoller@xen-trw1.site > date: Wed Dec 21 21:39:17 2005 -0500 > files: xen/arch/x86/svm_intr.c xen/arch/x86/svm_vmcb.c > description: > cleanup of svm specific code. > > > user: leendert@eserver2.watson.ibm.com > date: Wed Dec 21 17:18:25 2005 -0400 > files: tools/python/xen/xm/tests/test_create.py tools/xm-test/README > description: > Minor name cleanups. xm-test isn't VMX specific. Instead use HVM. > > > user: twoller@xen-trw1.site > date: Tue Dec 20 20:01:38 2005 -0500 > files: xen/arch/x86/svm_vmcb.c > description: > reword comments. > > > user: twoller@xen-trw1.site > date: Tue Dec 20 20:01:07 2005 -0500 > files: xen/arch/x86/svm_intr.c > description: > add additional VLAPIC delivery modes. > > > user: twoller@xen-trw1.site > date: Tue Dec 20 20:00:22 2005 -0500 > files: xen/arch/x86/svm.c > description: > reformat misaligned code. > > > user: twoller@xen-trw1.site > date: Tue Dec 20 19:59:37 2005 -0500 > files: xen/arch/x86/svm.c > description: > Add additional AMD SVM specific CPUID logic. > > > user: leendert@eserver2.watson.ibm.com > date: Thu Dec 15 03:06:15 2005 -0400 > files: tools/xm-test/tests/block-create/01_block_attach_device_pos.py tools/xm-test/tests/block-create/02_block_attach_file_device_pos.py tools/xm-test/tests/block-create/04_block_attach_device_repeatedly_pos.py tools/xm-test/tests/block-create/05_block_attach_and_dettach_device_repeatedly_pos.py tools/xm-test/tests/block-create/06_block_attach_baddomain_neg.py tools/xm-test/tests/block-create/07_block_attach_baddevice_neg.py tools/xm-test/tests/block-create/08_block_attach_bad_filedevice_neg.py tools/xm-test/tests/block-create/09_block_attach_and_dettach_device_check_data_pos.py tools/xm-test/tests/block-create/10_block_attach_dettach_multiple_devices.py tools/xm-test/tests/block-create/11_block_attach_shared_dom0.py tools/xm-test/tests/block-create/12_block_attach_shared_domU.py tools/xm-test/tests/block-destroy/01_block-destroy_btblock_pos.py tools/xm-test/tests/block-destroy/02_block-destroy_rtblock_pos.py tools/xm-test/tests/block-destroy/04_block-destroy_nonattached_neg.py tools/xm-test/tests/block-destroy/05_block-destroy_byname_pos.py tools/xm-test/tests/block-destroy/06_block-destroy_check_list_pos.py tools/xm-test/tests/block-list/01_block-list_pos.py tools/xm-test/tests/block-list/02_block-list_attachbd_pos.py tools/xm-test/tests/block-list/03_block-list_anotherbd_pos.py tools/xm-test/tests/block-list/04_block-list_nodb_pos.py tools/xm-test/tests/block-list/06_block-list_checkremove_pos.py tools/xm-test/tests/memmax/01_memmax_badparm_neg.py tools/xm-test/tests/memset/01_memset_basic_pos.py tools/xm-test/tests/memset/02_memset_badparm_neg.py tools/xm-test/tests/memset/03_memset_random_pos.py tools/xm-test/tests/memset/04_memset_smallmem_pos.py tools/xm-test/tests/migrate/01_migrate_localhost_pos.py tools/xm-test/tests/network-attach/01_network_attach_pos.py tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py tools/xm-test/tests/restore/01_restore_basic_pos.py tools/xm-test/tests/restore/02_restore_badparm_neg.py tools/xm-test/tests/restore/03_restore_badfilename_neg.py tools/xm-test/tests/restore/04_restore_withdevices_pos.py tools/xm-test/tests/save/01_save_basic_pos.py tools/xm-test/tests/save/02_save_badparm_neg.py tools/xm-test/tests/save/03_save_bogusfile_neg.py tools/xm-test/tests/sysrq/01_sysrq_basic_neg.py tools/xm-test/tests/sysrq/02_sysrq_sync_pos.py tools/xm-test/tests/sysrq/03_sysrq_withreboot_pos.py > description: > Adding SKIP() to tests that aren't supported for VMX domains. > > Signed-off-by: Dan Stekloff <dsteklof@us.ibm.com> > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Tue Dec 13 22:43:47 2005 -0400 > files: xen/arch/x86/svm.c xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/include/asm-x86/hvm_vpit.h xen/include/asm-x86/msr.h > description: > Support VMX guest accesses to IA32_TIME_STAMP_COUNTER MSR. > > Signed-off-by: Haifeng Xue <haifeng.xue@intel.com> > Signed-off-by: Leendert van Doorn <leendert@us.ibm.com> > > > user: twoller@xen-trw1.site > date: Tue Dec 13 19:49:53 2005 -0500 > files: xen/arch/x86/svm.c xen/arch/x86/svm_emulate.c xen/arch/x86/svm_instrlen.c xen/arch/x86/svm_intr.c xen/arch/x86/svm_vmcb.c xen/include/asm-x86/svm.h xen/include/asm-x86/svm_emulate.h xen/include/asm-x86/svm_intr.h xen/include/asm-x86/svm_vmcb.h xen/include/asm-x86/svm_vmmcall.h > description: > Add SVM base files to repository. > > > user: twoller@xen-trw1.site > date: Tue Dec 13 19:49:02 2005 -0500 > files: xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S > description: > Add SVM entry points for launch/resume. > > > user: twoller@xen-trw1.site > date: Tue Dec 13 19:47:38 2005 -0500 > files: .hgignore > description: > Add hvmloader files to ignore list. > > > user: leendert@eserver2.watson.ibm.com > date: Mon Dec 12 22:58:54 2005 -0400 > files: docs/src/user.tex tools/firmware/README xen/include/asm-x86/hvm.h > description: > Removed dirty words (by request). > > > user: leendert@eserver2.watson.ibm.com > date: Mon Dec 12 05:48:22 2005 -0400 > files: tools/firmware/hvmloader/mkhex > description: > Fix file mode. > > Signed-off-by: Leendert van Doorn <leendert@watson.ibm.com> > > > user: leendert@eserver2.watson.ibm.com > date: Mon Dec 12 04:50:42 2005 -0400 > files: xen/Rules.mk xen/arch/x86/cpu/amd.c xen/arch/x86/cpu/intel.c xen/arch/x86/dm/hvm_vioapic.c xen/arch/x86/dm/i8259.c xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/hvm.c xen/arch/x86/hvm_intercept.c xen/arch/x86/hvm_io.c xen/arch/x86/hvm_platform.c xen/arch/x86/hvm_vlapic.c xen/arch/x86/mpparse.c xen/arch/x86/shadow.c xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_vmcs.c xen/arch/x86/x86_32/asm-offsets.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/asm-offsets.c xen/arch/x86/x86_64/entry.S xen/arch/x86/x86_64/mm.c xen/include/asm-x86/config.h xen/include/asm-x86/cpufeature.h xen/include/asm-x86/domain.h xen/include/asm-x86/hvm_domain.h xen/include/asm-x86/hvm_io.h xen/include/asm-x86/hvm_support.h xen/include/asm-x86/hvm_vcpu.h xen/include/asm-x86/hvm_vioapic.h xen/include/asm-x86/hvm_vlapic.h xen/include/asm-x86/hvm_vpic.h xen/include/asm-x86/hvm_vpit.h xen/include/asm-x86/mpspec.h xen/include/asm-x86/msr.h xen/include/asm-x86/processor.h xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_cpu.h xen/include/asm-x86/vmx_vmcs.h > description: > Phase 3 of HVM integration: This patchset introduces the refactoring of > virtualization architecture independent functions from specific ones. > > > user: leendert@eserver2.watson.ibm.com > date: Sun Dec 11 07:02:51 2005 -0400 > files: xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/i387.c xen/arch/x86/shadow.c xen/arch/x86/vmx.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/traps.c xen/include/asm-x86/hvm.h xen/include/asm-x86/hvm_support.h xen/include/asm-x86/regs.h xen/include/asm-x86/shadow.h xen/include/asm-x86/vmx_vmcs.h > description: > Phase 2 of HVM integration: This patchset introduces the hvm interface > to the hypervisor and modifies all the non-vmx specific files to use it. > > > user: leendert@eserver2.watson.ibm.com > date: Sun Dec 11 01:10:00 2005 -0400 > files: tools/examples/Makefile tools/examples/README tools/examples/xmexample.hvm tools/ioemu/exec-all.h tools/ioemu/hw/i8254.c tools/ioemu/hw/i8259.c tools/ioemu/monitor.c tools/ioemu/target-i386-dm/helper2.c tools/ioemu/vl.c tools/libxc/Makefile tools/libxc/xc_hvm_build.c tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace_core.c tools/libxc/xenguest.h tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/image.py tools/python/xen/xm/create.py tools/xm-test/configure.ac tools/xm-test/lib/XmTestLib/XenDomain.py tools/xm-test/lib/XmTestLib/config.py.in tools/xm-test/ramdisk/Makefile.am tools/xm-test/ramdisk/bin/create_disk_image tools/xm-test/tests/block-list/04_block-list_nodb_pos.py xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h > description: > Phase 1 of HVM integration: This patchset updates the tools. Most of the > tools are machine independent except for some detection code in the hvm > domain builder.
850 lines
25 KiB
C
850 lines
25 KiB
C
/******************************************************************************
|
|
* xc_hvm_build.c
|
|
*/
|
|
|
|
#include <stddef.h>
|
|
#include "xg_private.h"
|
|
#define ELFSIZE 32
|
|
#include "xc_elf.h"
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <zlib.h>
|
|
#include <xen/hvm/hvm_info_table.h>
|
|
#include <xen/hvm/ioreq.h>
|
|
|
|
#define HVM_LOADER_ENTR_ADDR 0x00100000
|
|
|
|
#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
|
|
#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
|
|
#ifdef __x86_64__
|
|
#define L3_PROT (_PAGE_PRESENT)
|
|
#endif
|
|
|
|
#define E820MAX 128
|
|
|
|
#define E820_RAM 1
|
|
#define E820_RESERVED 2
|
|
#define E820_ACPI 3
|
|
#define E820_NVS 4
|
|
#define E820_IO 16
|
|
#define E820_SHARED_PAGE 17
|
|
#define E820_XENSTORE 18
|
|
|
|
#define E820_MAP_PAGE 0x00090000
|
|
#define E820_MAP_NR_OFFSET 0x000001E8
|
|
#define E820_MAP_OFFSET 0x000002D0
|
|
|
|
struct e820entry {
|
|
uint64_t addr;
|
|
uint64_t size;
|
|
uint32_t type;
|
|
} __attribute__((packed));
|
|
|
|
#define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
|
|
#define round_pgdown(_p) ((_p)&PAGE_MASK)
|
|
|
|
static int
|
|
parseelfimage(
|
|
char *elfbase, unsigned long elfsize, struct domain_setup_info *dsi);
|
|
static int
|
|
loadelfimage(
|
|
char *elfbase, int xch, uint32_t dom, unsigned long *parray,
|
|
struct domain_setup_info *dsi);
|
|
|
|
static unsigned char build_e820map(void *e820_page, unsigned long mem_size)
|
|
{
|
|
struct e820entry *e820entry =
|
|
(struct e820entry *)(((unsigned char *)e820_page) + E820_MAP_OFFSET);
|
|
unsigned char nr_map = 0;
|
|
|
|
/* XXX: Doesn't work for > 4GB yet */
|
|
e820entry[nr_map].addr = 0x0;
|
|
e820entry[nr_map].size = 0x9F800;
|
|
e820entry[nr_map].type = E820_RAM;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = 0x9F800;
|
|
e820entry[nr_map].size = 0x800;
|
|
e820entry[nr_map].type = E820_RESERVED;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = 0xA0000;
|
|
e820entry[nr_map].size = 0x20000;
|
|
e820entry[nr_map].type = E820_IO;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = 0xF0000;
|
|
e820entry[nr_map].size = 0x10000;
|
|
e820entry[nr_map].type = E820_RESERVED;
|
|
nr_map++;
|
|
|
|
#define STATIC_PAGES 2 /* for ioreq_t and store_mfn */
|
|
/* Most of the ram goes here */
|
|
e820entry[nr_map].addr = 0x100000;
|
|
e820entry[nr_map].size = mem_size - 0x100000 - STATIC_PAGES*PAGE_SIZE;
|
|
e820entry[nr_map].type = E820_RAM;
|
|
nr_map++;
|
|
|
|
/* Statically allocated special pages */
|
|
|
|
/* Shared ioreq_t page */
|
|
e820entry[nr_map].addr = mem_size - PAGE_SIZE;
|
|
e820entry[nr_map].size = PAGE_SIZE;
|
|
e820entry[nr_map].type = E820_SHARED_PAGE;
|
|
nr_map++;
|
|
|
|
/* For xenstore */
|
|
e820entry[nr_map].addr = mem_size - 2*PAGE_SIZE;
|
|
e820entry[nr_map].size = PAGE_SIZE;
|
|
e820entry[nr_map].type = E820_XENSTORE;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = mem_size;
|
|
e820entry[nr_map].size = 0x3 * PAGE_SIZE;
|
|
e820entry[nr_map].type = E820_NVS;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = mem_size + 0x3 * PAGE_SIZE;
|
|
e820entry[nr_map].size = 0xA * PAGE_SIZE;
|
|
e820entry[nr_map].type = E820_ACPI;
|
|
nr_map++;
|
|
|
|
e820entry[nr_map].addr = 0xFEC00000;
|
|
e820entry[nr_map].size = 0x1400000;
|
|
e820entry[nr_map].type = E820_IO;
|
|
nr_map++;
|
|
|
|
return (*(((unsigned char *)e820_page) + E820_MAP_NR_OFFSET) = nr_map);
|
|
}
|
|
|
|
static void
|
|
set_hvm_info_checksum(struct hvm_info_table *t)
|
|
{
|
|
uint8_t *ptr = (uint8_t *)t, sum = 0;
|
|
unsigned int i;
|
|
|
|
t->checksum = 0;
|
|
|
|
for (i = 0; i < t->length; i++)
|
|
sum += *ptr++;
|
|
|
|
t->checksum = -sum;
|
|
}
|
|
|
|
/*
|
|
* Use E820 reserved memory 0x9F800 to pass HVM info to vmxloader
|
|
* hvmloader will use this info to set BIOS accordingly
|
|
*/
|
|
static int set_hvm_info(int xc_handle, uint32_t dom,
|
|
unsigned long *pfn_list, unsigned int vcpus,
|
|
unsigned int acpi, unsigned int apic)
|
|
{
|
|
char *va_map;
|
|
struct hvm_info_table *va_hvm;
|
|
|
|
|
|
va_map = xc_map_foreign_range(
|
|
xc_handle,
|
|
dom,
|
|
PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
pfn_list[HVM_INFO_PFN]);
|
|
|
|
if ( va_map == NULL )
|
|
return -1;
|
|
|
|
va_hvm = (struct hvm_info_table *)(va_map + HVM_INFO_OFFSET);
|
|
memset(va_hvm, 0, sizeof(*va_hvm));
|
|
strncpy(va_hvm->signature, "HVM INFO", 8);
|
|
va_hvm->length = sizeof(struct hvm_info_table);
|
|
va_hvm->acpi_enabled = acpi;
|
|
va_hvm->apic_enabled = apic;
|
|
va_hvm->nr_vcpus = vcpus;
|
|
|
|
set_hvm_info_checksum(va_hvm);
|
|
|
|
munmap(va_map, PAGE_SIZE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef __i386__
|
|
static int zap_mmio_range(int xc_handle, uint32_t dom,
|
|
l2_pgentry_32_t *vl2tab,
|
|
unsigned long mmio_range_start,
|
|
unsigned long mmio_range_size)
|
|
{
|
|
unsigned long mmio_addr;
|
|
unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
|
|
unsigned long vl2e;
|
|
l1_pgentry_32_t *vl1tab;
|
|
|
|
mmio_addr = mmio_range_start & PAGE_MASK;
|
|
for (; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE) {
|
|
vl2e = vl2tab[l2_table_offset(mmio_addr)];
|
|
if (vl2e == 0)
|
|
continue;
|
|
vl1tab = xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE, vl2e >> PAGE_SHIFT);
|
|
if ( vl1tab == 0 )
|
|
{
|
|
PERROR("Failed zap MMIO range");
|
|
return -1;
|
|
}
|
|
vl1tab[l1_table_offset(mmio_addr)] = 0;
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int zap_mmio_ranges(int xc_handle, uint32_t dom, unsigned long l2tab,
|
|
unsigned char e820_map_nr, unsigned char *e820map)
|
|
{
|
|
unsigned int i;
|
|
struct e820entry *e820entry = (struct e820entry *)e820map;
|
|
|
|
l2_pgentry_32_t *vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l2tab >> PAGE_SHIFT);
|
|
if ( vl2tab == 0 )
|
|
return -1;
|
|
|
|
for ( i = 0; i < e820_map_nr; i++ )
|
|
{
|
|
if ( (e820entry[i].type == E820_IO) &&
|
|
(zap_mmio_range(xc_handle, dom, vl2tab,
|
|
e820entry[i].addr, e820entry[i].size) == -1))
|
|
return -1;
|
|
}
|
|
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
return 0;
|
|
}
|
|
#else
|
|
static int zap_mmio_range(int xc_handle, uint32_t dom,
|
|
l3_pgentry_t *vl3tab,
|
|
unsigned long mmio_range_start,
|
|
unsigned long mmio_range_size)
|
|
{
|
|
unsigned long mmio_addr;
|
|
unsigned long mmio_range_end = mmio_range_start + mmio_range_size;
|
|
unsigned long vl2e = 0;
|
|
unsigned long vl3e;
|
|
l1_pgentry_t *vl1tab;
|
|
l2_pgentry_t *vl2tab;
|
|
|
|
mmio_addr = mmio_range_start & PAGE_MASK;
|
|
for ( ; mmio_addr < mmio_range_end; mmio_addr += PAGE_SIZE )
|
|
{
|
|
vl3e = vl3tab[l3_table_offset(mmio_addr)];
|
|
if ( vl3e == 0 )
|
|
continue;
|
|
|
|
vl2tab = xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl3e>>PAGE_SHIFT);
|
|
if ( vl2tab == NULL )
|
|
{
|
|
PERROR("Failed zap MMIO range");
|
|
return -1;
|
|
}
|
|
|
|
vl2e = vl2tab[l2_table_offset(mmio_addr)];
|
|
if ( vl2e == 0 )
|
|
{
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
continue;
|
|
}
|
|
|
|
vl1tab = xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, vl2e>>PAGE_SHIFT);
|
|
if ( vl1tab == NULL )
|
|
{
|
|
PERROR("Failed zap MMIO range");
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
return -1;
|
|
}
|
|
|
|
vl1tab[l1_table_offset(mmio_addr)] = 0;
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int zap_mmio_ranges(int xc_handle, uint32_t dom, unsigned long l3tab,
|
|
unsigned char e820_map_nr, unsigned char *e820map)
|
|
{
|
|
unsigned int i;
|
|
struct e820entry *e820entry = (struct e820entry *)e820map;
|
|
|
|
l3_pgentry_t *vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l3tab >> PAGE_SHIFT);
|
|
if (vl3tab == 0)
|
|
return -1;
|
|
for ( i = 0; i < e820_map_nr; i++ ) {
|
|
if ( (e820entry[i].type == E820_IO) &&
|
|
(zap_mmio_range(xc_handle, dom, vl3tab,
|
|
e820entry[i].addr, e820entry[i].size) == -1) )
|
|
return -1;
|
|
}
|
|
munmap(vl3tab, PAGE_SIZE);
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
static int setup_guest(int xc_handle,
|
|
uint32_t dom, int memsize,
|
|
char *image, unsigned long image_size,
|
|
unsigned long nr_pages,
|
|
vcpu_guest_context_t *ctxt,
|
|
unsigned long shared_info_frame,
|
|
unsigned int control_evtchn,
|
|
unsigned int vcpus,
|
|
unsigned int acpi,
|
|
unsigned int apic,
|
|
unsigned int store_evtchn,
|
|
unsigned long *store_mfn)
|
|
{
|
|
l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
|
|
l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
|
|
unsigned long *page_array = NULL;
|
|
#ifdef __x86_64__
|
|
l3_pgentry_t *vl3tab=NULL;
|
|
unsigned long l3tab;
|
|
#endif
|
|
unsigned long l2tab = 0;
|
|
unsigned long l1tab = 0;
|
|
unsigned long count, i;
|
|
shared_info_t *shared_info;
|
|
void *e820_page;
|
|
unsigned char e820_map_nr;
|
|
xc_mmu_t *mmu = NULL;
|
|
int rc;
|
|
|
|
unsigned long nr_pt_pages;
|
|
unsigned long ppt_alloc;
|
|
|
|
struct domain_setup_info dsi;
|
|
unsigned long vpt_start;
|
|
unsigned long vpt_end;
|
|
unsigned long v_end;
|
|
|
|
unsigned long shared_page_frame = 0;
|
|
shared_iopage_t *sp;
|
|
|
|
memset(&dsi, 0, sizeof(struct domain_setup_info));
|
|
|
|
if ( (rc = parseelfimage(image, image_size, &dsi)) != 0 )
|
|
goto error_out;
|
|
|
|
if ( (dsi.v_start & (PAGE_SIZE-1)) != 0 )
|
|
{
|
|
PERROR("Guest OS must load to a page boundary.\n");
|
|
goto error_out;
|
|
}
|
|
|
|
/* memsize is in megabytes */
|
|
v_end = (unsigned long)memsize << 20;
|
|
|
|
#ifdef __i386__
|
|
nr_pt_pages = 1 + ((memsize + 3) >> 2);
|
|
#else
|
|
nr_pt_pages = 5 + ((memsize + 1) >> 1);
|
|
#endif
|
|
vpt_start = v_end;
|
|
vpt_end = vpt_start + (nr_pt_pages * PAGE_SIZE);
|
|
|
|
printf("VIRTUAL MEMORY ARRANGEMENT:\n"
|
|
" Loaded HVM loader: %08lx->%08lx\n"
|
|
" Page tables: %08lx->%08lx\n"
|
|
" TOTAL: %08lx->%08lx\n",
|
|
dsi.v_kernstart, dsi.v_kernend,
|
|
vpt_start, vpt_end,
|
|
dsi.v_start, v_end);
|
|
printf(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
|
|
|
|
if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
|
|
{
|
|
ERROR("Initial guest OS requires too much space\n"
|
|
"(%luMB is greater than %luMB limit)\n",
|
|
(v_end-dsi.v_start)>>20, (nr_pages<<PAGE_SHIFT)>>20);
|
|
goto error_out;
|
|
}
|
|
|
|
if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
|
|
{
|
|
PERROR("Could not allocate memory");
|
|
goto error_out;
|
|
}
|
|
|
|
if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
|
|
{
|
|
PERROR("Could not get the page frame list");
|
|
goto error_out;
|
|
}
|
|
|
|
loadelfimage(image, xc_handle, dom, page_array, &dsi);
|
|
|
|
if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL )
|
|
goto error_out;
|
|
|
|
/* First allocate page for page dir or pdpt */
|
|
ppt_alloc = vpt_start >> PAGE_SHIFT;
|
|
if ( page_array[ppt_alloc] > 0xfffff )
|
|
{
|
|
unsigned long nmfn;
|
|
nmfn = xc_make_page_below_4G( xc_handle, dom, page_array[ppt_alloc] );
|
|
if ( nmfn == 0 )
|
|
{
|
|
fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
|
|
goto error_out;
|
|
}
|
|
page_array[ppt_alloc] = nmfn;
|
|
}
|
|
|
|
#ifdef __i386__
|
|
l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
|
|
ctxt->ctrlreg[3] = l2tab;
|
|
|
|
if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l2tab >> PAGE_SHIFT)) == NULL )
|
|
goto error_out;
|
|
memset(vl2tab, 0, PAGE_SIZE);
|
|
vl2e = &vl2tab[l2_table_offset(0)];
|
|
for ( count = 0; count < (v_end >> PAGE_SHIFT); count++ )
|
|
{
|
|
if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
|
|
{
|
|
l1tab = page_array[ppt_alloc++] << PAGE_SHIFT;
|
|
if ( vl1tab != NULL )
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l1tab >> PAGE_SHIFT)) == NULL )
|
|
{
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
goto error_out;
|
|
}
|
|
memset(vl1tab, 0, PAGE_SIZE);
|
|
vl1e = &vl1tab[l1_table_offset(count << PAGE_SHIFT)];
|
|
*vl2e++ = l1tab | L2_PROT;
|
|
}
|
|
|
|
*vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
|
|
vl1e++;
|
|
}
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
#else
|
|
l3tab = page_array[ppt_alloc++] << PAGE_SHIFT;
|
|
ctxt->ctrlreg[3] = l3tab;
|
|
|
|
if ( (vl3tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l3tab >> PAGE_SHIFT)) == NULL )
|
|
goto error_out;
|
|
memset(vl3tab, 0, PAGE_SIZE);
|
|
|
|
/* Fill in every PDPT entry. */
|
|
for ( i = 0; i < L3_PAGETABLE_ENTRIES_PAE; i++ )
|
|
{
|
|
l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
|
|
if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l2tab >> PAGE_SHIFT)) == NULL )
|
|
goto error_out;
|
|
memset(vl2tab, 0, PAGE_SIZE);
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
vl2tab = NULL;
|
|
vl3tab[i] = l2tab | L3_PROT;
|
|
}
|
|
|
|
for ( count = 0; count < (v_end >> PAGE_SHIFT); count++ )
|
|
{
|
|
if ( !(count & ((1 << (L3_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)) - 1)) )
|
|
{
|
|
l2tab = vl3tab[count >> (L3_PAGETABLE_SHIFT - L1_PAGETABLE_SHIFT)]
|
|
& PAGE_MASK;
|
|
|
|
if (vl2tab != NULL)
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
|
|
if ( (vl2tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l2tab >> PAGE_SHIFT)) == NULL )
|
|
goto error_out;
|
|
|
|
vl2e = &vl2tab[l2_table_offset(count << PAGE_SHIFT)];
|
|
}
|
|
if ( ((unsigned long)vl1e & (PAGE_SIZE-1)) == 0 )
|
|
{
|
|
l1tab = page_array[ppt_alloc++] << PAGE_SHIFT;
|
|
if ( vl1tab != NULL )
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
if ( (vl1tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
|
|
PROT_READ|PROT_WRITE,
|
|
l1tab >> PAGE_SHIFT)) == NULL )
|
|
{
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
goto error_out;
|
|
}
|
|
memset(vl1tab, 0, PAGE_SIZE);
|
|
vl1e = &vl1tab[l1_table_offset(count << PAGE_SHIFT)];
|
|
*vl2e++ = l1tab | L2_PROT;
|
|
}
|
|
|
|
*vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
|
|
vl1e++;
|
|
}
|
|
|
|
munmap(vl1tab, PAGE_SIZE);
|
|
munmap(vl2tab, PAGE_SIZE);
|
|
munmap(vl3tab, PAGE_SIZE);
|
|
#endif
|
|
/* Write the machine->phys table entries. */
|
|
for ( count = 0; count < nr_pages; count++ )
|
|
{
|
|
if ( xc_add_mmu_update(xc_handle, mmu,
|
|
(page_array[count] << PAGE_SHIFT) |
|
|
MMU_MACHPHYS_UPDATE, count) )
|
|
goto error_out;
|
|
}
|
|
|
|
if ( set_hvm_info(xc_handle, dom, page_array, vcpus, acpi, apic) ) {
|
|
fprintf(stderr, "Couldn't set hvm info for HVM guest.\n");
|
|
goto error_out;
|
|
}
|
|
|
|
if ( (e820_page = xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
|
|
page_array[E820_MAP_PAGE >> PAGE_SHIFT])) == 0 )
|
|
goto error_out;
|
|
memset(e820_page, 0, PAGE_SIZE);
|
|
e820_map_nr = build_e820map(e820_page, v_end);
|
|
#if defined (__i386__)
|
|
if (zap_mmio_ranges(xc_handle, dom, l2tab, e820_map_nr,
|
|
((unsigned char *)e820_page) + E820_MAP_OFFSET) == -1)
|
|
#else
|
|
if (zap_mmio_ranges(xc_handle, dom, l3tab, e820_map_nr,
|
|
((unsigned char *)e820_page) + E820_MAP_OFFSET) == -1)
|
|
#endif
|
|
goto error_out;
|
|
munmap(e820_page, PAGE_SIZE);
|
|
|
|
/* shared_info page starts its life empty. */
|
|
if ( (shared_info = xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
|
|
shared_info_frame)) == 0 )
|
|
goto error_out;
|
|
memset(shared_info, 0, sizeof(shared_info_t));
|
|
/* Mask all upcalls... */
|
|
for ( i = 0; i < MAX_VIRT_CPUS; i++ )
|
|
shared_info->vcpu_info[i].evtchn_upcall_mask = 1;
|
|
munmap(shared_info, PAGE_SIZE);
|
|
|
|
/* Populate the event channel port in the shared page */
|
|
shared_page_frame = page_array[(v_end >> PAGE_SHIFT) - 1];
|
|
if ( (sp = (shared_iopage_t *) xc_map_foreign_range(
|
|
xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
|
|
shared_page_frame)) == 0 )
|
|
goto error_out;
|
|
memset(sp, 0, PAGE_SIZE);
|
|
sp->sp_global.eport = control_evtchn;
|
|
munmap(sp, PAGE_SIZE);
|
|
|
|
*store_mfn = page_array[(v_end >> PAGE_SHIFT) - 2];
|
|
if ( xc_clear_domain_page(xc_handle, dom, *store_mfn) )
|
|
goto error_out;
|
|
|
|
/* Send the page update requests down to the hypervisor. */
|
|
if ( xc_finish_mmu_updates(xc_handle, mmu) )
|
|
goto error_out;
|
|
|
|
free(mmu);
|
|
free(page_array);
|
|
|
|
/*
|
|
* Initial register values:
|
|
*/
|
|
ctxt->user_regs.ds = 0;
|
|
ctxt->user_regs.es = 0;
|
|
ctxt->user_regs.fs = 0;
|
|
ctxt->user_regs.gs = 0;
|
|
ctxt->user_regs.ss = 0;
|
|
ctxt->user_regs.cs = 0;
|
|
ctxt->user_regs.eip = dsi.v_kernentry;
|
|
ctxt->user_regs.edx = 0;
|
|
ctxt->user_regs.eax = 0;
|
|
ctxt->user_regs.esp = 0;
|
|
ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot cpu */
|
|
ctxt->user_regs.ecx = 0;
|
|
ctxt->user_regs.esi = 0;
|
|
ctxt->user_regs.edi = 0;
|
|
ctxt->user_regs.ebp = 0;
|
|
|
|
ctxt->user_regs.eflags = 0;
|
|
|
|
return 0;
|
|
|
|
error_out:
|
|
free(mmu);
|
|
free(page_array);
|
|
return -1;
|
|
}
|
|
|
|
int xc_hvm_build(int xc_handle,
|
|
uint32_t domid,
|
|
int memsize,
|
|
const char *image_name,
|
|
unsigned int control_evtchn,
|
|
unsigned int vcpus,
|
|
unsigned int acpi,
|
|
unsigned int apic,
|
|
unsigned int store_evtchn,
|
|
unsigned long *store_mfn)
|
|
{
|
|
dom0_op_t launch_op, op;
|
|
int rc, i;
|
|
vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
|
|
unsigned long nr_pages;
|
|
char *image = NULL;
|
|
unsigned long image_size;
|
|
xen_capabilities_info_t xen_caps;
|
|
|
|
if ( (rc = xc_version(xc_handle, XENVER_capabilities, &xen_caps)) != 0 )
|
|
{
|
|
PERROR("Failed to get xen version info");
|
|
goto error_out;
|
|
}
|
|
|
|
if ( !strstr(xen_caps, "hvm") )
|
|
{
|
|
PERROR("CPU doesn't support HVM extensions or "
|
|
"the extensions are not enabled");
|
|
goto error_out;
|
|
}
|
|
|
|
if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
|
|
{
|
|
PERROR("Could not find total pages for domain");
|
|
goto error_out;
|
|
}
|
|
|
|
if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
|
|
goto error_out;
|
|
|
|
if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
|
|
{
|
|
PERROR("%s: ctxt mlock failed", __func__);
|
|
return 1;
|
|
}
|
|
|
|
op.cmd = DOM0_GETDOMAININFO;
|
|
op.u.getdomaininfo.domain = (domid_t)domid;
|
|
if ( (xc_dom0_op(xc_handle, &op) < 0) ||
|
|
((uint16_t)op.u.getdomaininfo.domain != domid) )
|
|
{
|
|
PERROR("Could not get info on domain");
|
|
goto error_out;
|
|
}
|
|
|
|
memset(ctxt, 0, sizeof(*ctxt));
|
|
|
|
ctxt->flags = VGCF_HVM_GUEST;
|
|
if ( setup_guest(xc_handle, domid, memsize, image, image_size, nr_pages,
|
|
ctxt, op.u.getdomaininfo.shared_info_frame, control_evtchn,
|
|
vcpus, acpi, apic, store_evtchn, store_mfn) < 0)
|
|
{
|
|
ERROR("Error constructing guest OS");
|
|
goto error_out;
|
|
}
|
|
|
|
free(image);
|
|
|
|
/* FPU is set up to default initial state. */
|
|
memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
|
|
|
|
/* Virtual IDT is empty at start-of-day. */
|
|
for ( i = 0; i < 256; i++ )
|
|
{
|
|
ctxt->trap_ctxt[i].vector = i;
|
|
ctxt->trap_ctxt[i].cs = FLAT_KERNEL_CS;
|
|
}
|
|
|
|
/* No LDT. */
|
|
ctxt->ldt_ents = 0;
|
|
|
|
/* Use the default Xen-provided GDT. */
|
|
ctxt->gdt_ents = 0;
|
|
|
|
/* No debugging. */
|
|
memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
|
|
|
|
/* No callback handlers. */
|
|
#if defined(__i386__)
|
|
ctxt->event_callback_cs = FLAT_KERNEL_CS;
|
|
ctxt->event_callback_eip = 0;
|
|
ctxt->failsafe_callback_cs = FLAT_KERNEL_CS;
|
|
ctxt->failsafe_callback_eip = 0;
|
|
#elif defined(__x86_64__)
|
|
ctxt->event_callback_eip = 0;
|
|
ctxt->failsafe_callback_eip = 0;
|
|
ctxt->syscall_callback_eip = 0;
|
|
#endif
|
|
|
|
memset( &launch_op, 0, sizeof(launch_op) );
|
|
|
|
launch_op.u.setvcpucontext.domain = (domid_t)domid;
|
|
launch_op.u.setvcpucontext.vcpu = 0;
|
|
launch_op.u.setvcpucontext.ctxt = ctxt;
|
|
|
|
launch_op.cmd = DOM0_SETVCPUCONTEXT;
|
|
rc = xc_dom0_op(xc_handle, &launch_op);
|
|
|
|
return rc;
|
|
|
|
error_out:
|
|
free(image);
|
|
return -1;
|
|
}
|
|
|
|
static inline int is_loadable_phdr(Elf32_Phdr *phdr)
|
|
{
|
|
return ((phdr->p_type == PT_LOAD) &&
|
|
((phdr->p_flags & (PF_W|PF_X)) != 0));
|
|
}
|
|
|
|
static int parseelfimage(char *elfbase,
|
|
unsigned long elfsize,
|
|
struct domain_setup_info *dsi)
|
|
{
|
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elfbase;
|
|
Elf32_Phdr *phdr;
|
|
Elf32_Shdr *shdr;
|
|
unsigned long kernstart = ~0UL, kernend=0UL;
|
|
char *shstrtab;
|
|
int h;
|
|
|
|
if ( !IS_ELF(*ehdr) )
|
|
{
|
|
ERROR("Kernel image does not have an ELF header.");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if ( (ehdr->e_phoff + (ehdr->e_phnum * ehdr->e_phentsize)) > elfsize )
|
|
{
|
|
ERROR("ELF program headers extend beyond end of image.");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if ( (ehdr->e_shoff + (ehdr->e_shnum * ehdr->e_shentsize)) > elfsize )
|
|
{
|
|
ERROR("ELF section headers extend beyond end of image.");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Find the section-header strings table. */
|
|
if ( ehdr->e_shstrndx == SHN_UNDEF )
|
|
{
|
|
ERROR("ELF image has no section-header strings table (shstrtab).");
|
|
return -EINVAL;
|
|
}
|
|
shdr = (Elf32_Shdr *)(elfbase + ehdr->e_shoff +
|
|
(ehdr->e_shstrndx*ehdr->e_shentsize));
|
|
shstrtab = elfbase + shdr->sh_offset;
|
|
|
|
for ( h = 0; h < ehdr->e_phnum; h++ )
|
|
{
|
|
phdr = (Elf32_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
|
|
if ( !is_loadable_phdr(phdr) )
|
|
continue;
|
|
if ( phdr->p_paddr < kernstart )
|
|
kernstart = phdr->p_paddr;
|
|
if ( (phdr->p_paddr + phdr->p_memsz) > kernend )
|
|
kernend = phdr->p_paddr + phdr->p_memsz;
|
|
}
|
|
|
|
if ( (kernstart > kernend) ||
|
|
(ehdr->e_entry < kernstart) ||
|
|
(ehdr->e_entry > kernend) )
|
|
{
|
|
ERROR("Malformed ELF image.");
|
|
return -EINVAL;
|
|
}
|
|
|
|
dsi->v_start = 0x00000000;
|
|
|
|
dsi->v_kernstart = kernstart;
|
|
dsi->v_kernend = kernend;
|
|
dsi->v_kernentry = HVM_LOADER_ENTR_ADDR;
|
|
|
|
dsi->v_end = dsi->v_kernend;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
loadelfimage(
|
|
char *elfbase, int xch, uint32_t dom, unsigned long *parray,
|
|
struct domain_setup_info *dsi)
|
|
{
|
|
Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elfbase;
|
|
Elf32_Phdr *phdr;
|
|
int h;
|
|
|
|
char *va;
|
|
unsigned long pa, done, chunksz;
|
|
|
|
for ( h = 0; h < ehdr->e_phnum; h++ )
|
|
{
|
|
phdr = (Elf32_Phdr *)(elfbase + ehdr->e_phoff + (h*ehdr->e_phentsize));
|
|
if ( !is_loadable_phdr(phdr) )
|
|
continue;
|
|
|
|
for ( done = 0; done < phdr->p_filesz; done += chunksz )
|
|
{
|
|
pa = (phdr->p_paddr + done) - dsi->v_start;
|
|
if ((va = xc_map_foreign_range(
|
|
xch, dom, PAGE_SIZE, PROT_WRITE,
|
|
parray[pa >> PAGE_SHIFT])) == 0)
|
|
return -1;
|
|
chunksz = phdr->p_filesz - done;
|
|
if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
|
|
chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
|
|
memcpy(va + (pa & (PAGE_SIZE-1)),
|
|
elfbase + phdr->p_offset + done, chunksz);
|
|
munmap(va, PAGE_SIZE);
|
|
}
|
|
|
|
for ( ; done < phdr->p_memsz; done += chunksz )
|
|
{
|
|
pa = (phdr->p_paddr + done) - dsi->v_start;
|
|
if ((va = xc_map_foreign_range(
|
|
xch, dom, PAGE_SIZE, PROT_WRITE,
|
|
parray[pa >> PAGE_SHIFT])) == 0)
|
|
return -1;
|
|
chunksz = phdr->p_memsz - done;
|
|
if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
|
|
chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
|
|
memset(va + (pa & (PAGE_SIZE-1)), 0, chunksz);
|
|
munmap(va, PAGE_SIZE);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Local variables:
|
|
* mode: C
|
|
* c-set-style: "BSD"
|
|
* c-basic-offset: 4
|
|
* tab-width: 4
|
|
* indent-tabs-mode: nil
|
|
* End:
|
|
*/
|