diff --git a/install.sh b/install.sh index e7dbfc24b6..d51bc51eab 100755 --- a/install.sh +++ b/install.sh @@ -28,7 +28,7 @@ cp -fdRL $src/etc/init.d/* $dst/etc/init.d/ echo "All done." [ -x "$(which udevinfo)" ] && \ - UDEV_VERSION=$(udevinfo -V | sed -e 's/^.*\s\([0-9]\+\)[^0-9]*/\1/') + UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/') if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then cp -f $src/etc/udev/rules.d/*.rules $dst/etc/udev/rules.d/ diff --git a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c index 0b0084b31e..dff9343c5f 100644 --- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c +++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c @@ -213,55 +213,6 @@ static int privcmd_ioctl(struct inode *inode, struct file *file, break; #endif -#ifndef __ia64__ - case IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS: { - pgd_t *pgd; - pud_t *pud; - pmd_t *pmd; - unsigned long m2pv, m2p_mfn; - privcmd_m2pmfns_t m; - unsigned long __user *p; - int i; - -#if defined (__x86_64__) - /* - ** XXX SMH: the below procedure won't work for 64 since - ** we don't have access to the memory which maps the M2P. - ** A proper fix will probably involve moving this - ** functionality to Xen - for now just return an error - ** here rather than GPF'ing in the kernel. - */ - ret = -EINVAL; - break; -#endif - - if (copy_from_user(&m, udata, sizeof(m))) - return -EFAULT; - - m2pv = (unsigned long)machine_to_phys_mapping; - - p = m.arr; - - for (i=0; i < m.num; i++) { - pgd = pgd_offset_k(m2pv); - pud = pud_offset(pgd, m2pv); - pmd = pmd_offset(pud, m2pv); - m2p_mfn = (*(uint64_t *)pmd >> PAGE_SHIFT)&0xFFFFFFFF; - m2p_mfn += pte_index(m2pv); - - if (put_user(m2p_mfn, p + i)) - return -EFAULT; - - m2pv += (1 << 21); - } - - ret = 0; - break; - - } - break; -#endif - default: ret = -EINVAL; break; diff --git a/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h b/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h index 3c91205855..074d66c79b 100644 --- a/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h +++ b/linux-2.6-xen-sparse/include/asm-xen/linux-public/privcmd.h @@ -59,11 +59,6 @@ typedef struct privcmd_mmapbatch { unsigned long __user *arr; /* array of mfns - top nibble set on err */ } privcmd_mmapbatch_t; -typedef struct privcmd_m2pmfns { - int num; /* max number of mfns to return */ - unsigned long __user *arr; /* array of mfns */ -} privcmd_m2pmfns_t; - typedef struct privcmd_blkmsg { unsigned long op; @@ -82,8 +77,6 @@ typedef struct privcmd_blkmsg _IOC(_IOC_NONE, 'P', 2, sizeof(privcmd_mmap_t)) #define IOCTL_PRIVCMD_MMAPBATCH \ _IOC(_IOC_NONE, 'P', 3, sizeof(privcmd_mmapbatch_t)) -#define IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS \ - _IOC(_IOC_READ, 'P', 4, sizeof(unsigned long)) #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */ diff --git a/tools/check/check_hotplug b/tools/check/check_hotplug index aaedb767bf..999c7d8e2e 100644 --- a/tools/check/check_hotplug +++ b/tools/check/check_hotplug @@ -7,7 +7,7 @@ function error { exit 1 } [ -x "$(which udevinfo)" ] && \ - UDEV_VERSION=$(udevinfo -V | sed -e 's/^.*\s\([0-9]\+\)[^0-9]*/\1/') + UDEV_VERSION=$(udevinfo -V | sed -e 's/^[^0-9]* \([0-9]\{1,\}\)[^0-9]\{0,\}/\1/') if [ -n "$UDEV_VERSION" ] && [ $UDEV_VERSION -ge 059 ]; then exit 0 diff --git a/tools/libxc/xc_linux_restore.c b/tools/libxc/xc_linux_restore.c index 20dfde7d98..674915904c 100644 --- a/tools/libxc/xc_linux_restore.c +++ b/tools/libxc/xc_linux_restore.c @@ -78,6 +78,7 @@ int uncanonicalize_pagetable(unsigned long type, void *page) pfn = (pte >> PAGE_SHIFT) & 0xffffffff; if(pfn >= max_pfn) { + /* This "page table page" is probably not one; bail. */ ERR("Frame number in type %lu page table is out of range: " "i=%d pfn=0x%lx max_pfn=%lu", type >> 28, i, pfn, max_pfn); @@ -111,6 +112,7 @@ int xc_linux_restore(int xc_handle, int io_fd, unsigned long mfn, pfn; unsigned int prev_pc, this_pc; int verify = 0; + int nraces = 0; /* The new domain's shared-info frame number. */ unsigned long shared_info_frame; @@ -344,8 +346,15 @@ int xc_linux_restore(int xc_handle, int io_fd, if(pt_levels != 3 || pagetype != L1TAB) { if(!uncanonicalize_pagetable(pagetype, page)) { - ERR("failed uncanonicalize pt!\n"); - goto out; + /* + ** Failing to uncanonicalize a page table can be ok + ** under live migration since the pages type may have + ** changed by now (and we'll get an update later). + */ + DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n", + pagetype >> 28, pfn, mfn); + nraces++; + continue; } } @@ -394,7 +403,7 @@ int xc_linux_restore(int xc_handle, int io_fd, n+= j; /* crude stats */ } - DPRINTF("Received all pages\n"); + DPRINTF("Received all pages (%d races)\n", nraces); if(pt_levels == 3) { diff --git a/tools/libxc/xc_linux_save.c b/tools/libxc/xc_linux_save.c index af2aec1fb1..467598fec4 100644 --- a/tools/libxc/xc_linux_save.c +++ b/tools/libxc/xc_linux_save.c @@ -502,7 +502,7 @@ static unsigned long *xc_map_m2p(int xc_handle, unsigned long max_mfn, int prot) { - privcmd_m2pmfns_t m2p_mfns; + struct xen_machphys_mfn_list xmml; privcmd_mmap_t ioctlx; privcmd_mmap_entry_t *entries; unsigned long m2p_chunks, m2p_size; @@ -512,50 +512,45 @@ static unsigned long *xc_map_m2p(int xc_handle, m2p_size = M2P_SIZE(max_mfn); m2p_chunks = M2P_CHUNKS(max_mfn); - - m2p_mfns.num = m2p_chunks; - - if(!(m2p_mfns.arr = malloc(m2p_chunks * sizeof(unsigned long)))) { + xmml.max_extents = m2p_chunks; + if (!(xmml.extent_start = malloc(m2p_chunks * sizeof(unsigned long)))) { ERR("failed to allocate space for m2p mfns!\n"); return NULL; } - if (ioctl(xc_handle, IOCTL_PRIVCMD_GET_MACH2PHYS_MFNS, &m2p_mfns) < 0) { + if (xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) || + (xmml.nr_extents != m2p_chunks)) { ERR("xc_get_m2p_mfns:"); return NULL; } - if((m2p = mmap(NULL, m2p_size, prot, - MAP_SHARED, xc_handle, 0)) == MAP_FAILED) { + if ((m2p = mmap(NULL, m2p_size, prot, + MAP_SHARED, xc_handle, 0)) == MAP_FAILED) { ERR("failed to mmap m2p"); return NULL; } - - if(!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { + if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { ERR("failed to allocate space for mmap entries!\n"); return NULL; } - ioctlx.num = m2p_chunks; ioctlx.dom = DOMID_XEN; ioctlx.entry = entries; - for(i=0; i < m2p_chunks; i++) { - + for (i=0; i < m2p_chunks; i++) { entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE)); - entries[i].mfn = m2p_mfns.arr[i]; + entries[i].mfn = xmml.extent_start[i]; entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT; - } - if((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) { + if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) { ERR("ioctl_mmap failed (rc = %d)", rc); return NULL; } - - free(m2p_mfns.arr); + + free(xmml.extent_start); free(entries); return m2p; diff --git a/tools/libxc/xc_private.c b/tools/libxc/xc_private.c index 2c7759336e..75556f6847 100644 --- a/tools/libxc/xc_private.c +++ b/tools/libxc/xc_private.c @@ -190,6 +190,7 @@ int xc_memory_op(int xc_handle, { DECLARE_HYPERCALL; struct xen_memory_reservation *reservation = arg; + struct xen_machphys_mfn_list *xmml = arg; long ret = -EINVAL; hypercall.op = __HYPERVISOR_memory_op; @@ -214,6 +215,20 @@ int xc_memory_op(int xc_handle, goto out1; } break; + case XENMEM_machphys_mfn_list: + if ( mlock(xmml, sizeof(*xmml)) != 0 ) + { + PERROR("Could not mlock"); + goto out1; + } + if ( mlock(xmml->extent_start, + xmml->max_extents * sizeof(unsigned long)) != 0 ) + { + PERROR("Could not mlock"); + safe_munlock(xmml, sizeof(*xmml)); + goto out1; + } + break; } ret = do_xen_hypercall(xc_handle, &hypercall); @@ -227,6 +242,11 @@ int xc_memory_op(int xc_handle, safe_munlock(reservation->extent_start, reservation->nr_extents * sizeof(unsigned long)); break; + case XENMEM_machphys_mfn_list: + safe_munlock(xmml, sizeof(*xmml)); + safe_munlock(xmml->extent_start, + xmml->max_extents * sizeof(unsigned long)); + break; } out1: diff --git a/tools/xm-test/configure.ac b/tools/xm-test/configure.ac index 224d5fa129..b2edf49457 100644 --- a/tools/xm-test/configure.ac +++ b/tools/xm-test/configure.ac @@ -35,6 +35,7 @@ AC_CONFIG_FILES([ Makefile ramdisk/Makefile tests/Makefile + tests/_sanity/Makefile tests/block-list/Makefile tests/block-create/Makefile tests/block-destroy/Makefile diff --git a/tools/xm-test/runtest.sh b/tools/xm-test/runtest.sh index f366a48c74..25aa2d842d 100755 --- a/tools/xm-test/runtest.sh +++ b/tools/xm-test/runtest.sh @@ -14,6 +14,7 @@ usage() { echo " -q : run a quick test set" echo " -e : set email address for report" echo " -s : just submit report " + echo " -h | --help : show this help" } # Just submit the report @@ -86,6 +87,15 @@ runnable_tests() { exit 1 fi + # Run a few sample tests to make sure things are working + # before we take the plunge + echo "Running sanity checks..." + make -C tests/_sanity check 2>&1 | grep REASON + if [ $? -eq 0 ]; then + echo "Sanity checks failed" + exit 1 + fi + } # Get contact info if needed @@ -119,7 +129,7 @@ get_contact_info() { # Run the tests run_tests() { output=$1 - echo Running tests... + echo Running real tests... TEST_VERBOSE=1 make -k check > $output 2>&1 } @@ -209,6 +219,10 @@ while [ $# -gt 0 ] -s) run=no ;; + -h|--help) + usage + exit 0 + ;; *) REPORT=$1 break diff --git a/tools/xm-test/tests/_sanity/01_domu_proc.py b/tools/xm-test/tests/_sanity/01_domu_proc.py new file mode 100644 index 0000000000..56eb391bed --- /dev/null +++ b/tools/xm-test/tests/_sanity/01_domu_proc.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +# Copyright (C) International Business Machines Corp., 2005 +# Author: Dan Smith + +# +# Test that the library and ramdisk are working to the point +# that we can start a DomU and read /proc +# + +from XmTestLib import * + +import re + +domain = XmTestDomain() + +try: + domain.start() +except DomainError, e: + FAIL(str(e)) + +try: + console = XmConsole(domain.getName()) + console.sendInput("foo") + run = console.runCmd("cat /proc/cpuinfo") +except ConsoleError, e: + FAIL(str(e)) + +if run["return"] != 0: + FAIL("Unable to read /proc/cpuinfo") + +if not re.search("processor", run["output"]): + print run["output"] + FAIL("/proc/cpuinfo looks wrong!") diff --git a/tools/xm-test/tests/_sanity/Makefile.am b/tools/xm-test/tests/_sanity/Makefile.am new file mode 100644 index 0000000000..c1525b3f44 --- /dev/null +++ b/tools/xm-test/tests/_sanity/Makefile.am @@ -0,0 +1,21 @@ + +SUBDIRS = + +TESTS = 01_domu_proc.test + +XFAIL_TESTS = + +EXTRA_DIST = $(TESTS) $(XFAIL_TESTS) + +TESTS_ENVIRONMENT=@TENV@ + +%.test: %.py + cp $< $@ + chmod +x $@ + +clean-local: am_config_clean-local + +am_config_clean-local: + rm -f *test + rm -f *log + rm -f *~ diff --git a/tools/xm-test/tests/network-attach/network_utils.py b/tools/xm-test/tests/network-attach/network_utils.py index a1ccdf6ac4..16c521b43a 100644 --- a/tools/xm-test/tests/network-attach/network_utils.py +++ b/tools/xm-test/tests/network-attach/network_utils.py @@ -10,7 +10,7 @@ def count_eth(console): run = console.runCmd("ifconfig -a | grep eth") except ConsoleError, e: FAIL(str(e)) - return = len(run['output'].splitlines()) + return len(run['output'].splitlines()) def network_attach(domain_name, console): eths_before = count_eth(console) diff --git a/xen/arch/x86/shadow32.c b/xen/arch/x86/shadow32.c index 8a0e81b707..0df797a14f 100644 --- a/xen/arch/x86/shadow32.c +++ b/xen/arch/x86/shadow32.c @@ -800,13 +800,10 @@ void free_monitor_pagetable(struct vcpu *v) /* * Then free monitor_table. - * Note: for VMX guest, only BSP need do this free. */ - if (!(VMX_DOMAIN(v) && v->vcpu_id)) { - mfn = pagetable_get_pfn(v->arch.monitor_table); - unmap_domain_page(v->arch.monitor_vtable); - free_domheap_page(&frame_table[mfn]); - } + mfn = pagetable_get_pfn(v->arch.monitor_table); + unmap_domain_page(v->arch.monitor_vtable); + free_domheap_page(&frame_table[mfn]); v->arch.monitor_table = mk_pagetable(0); v->arch.monitor_vtable = 0; diff --git a/xen/arch/x86/shadow_public.c b/xen/arch/x86/shadow_public.c index cc91811e34..69f7c0b7d6 100644 --- a/xen/arch/x86/shadow_public.c +++ b/xen/arch/x86/shadow_public.c @@ -297,13 +297,11 @@ void free_monitor_pagetable(struct vcpu *v) /* * free monitor_table. - * Note: for VMX guest, only BSP need do this free. */ - if (!(VMX_DOMAIN(v) && v->vcpu_id)) { - mfn = pagetable_get_pfn(v->arch.monitor_table); - unmap_domain_page(v->arch.monitor_vtable); - free_domheap_page(&frame_table[mfn]); - } + mfn = pagetable_get_pfn(v->arch.monitor_table); + unmap_domain_page(v->arch.monitor_vtable); + free_domheap_page(&frame_table[mfn]); + v->arch.monitor_table = mk_pagetable(0); v->arch.monitor_vtable = 0; } @@ -396,18 +394,15 @@ void free_monitor_pagetable(struct vcpu *v) /* * Then free monitor_table. - * Note: for VMX guest, only BSP need do this free. */ - if (!(VMX_DOMAIN(v) && v->vcpu_id)) { - mfn = pagetable_get_pfn(v->arch.monitor_table); - unmap_domain_page(v->arch.monitor_vtable); - free_domheap_page(&frame_table[mfn]); - } + mfn = pagetable_get_pfn(v->arch.monitor_table); + unmap_domain_page(v->arch.monitor_vtable); + free_domheap_page(&frame_table[mfn]); v->arch.monitor_table = mk_pagetable(0); v->arch.monitor_vtable = 0; } -#endif +#endif static void shadow_free_snapshot(struct domain *d, struct out_of_sync_entry *entry) diff --git a/xen/arch/x86/x86_32/mm.c b/xen/arch/x86/x86_32/mm.c index 798865d370..d1c625956a 100644 --- a/xen/arch/x86/x86_32/mm.c +++ b/xen/arch/x86/x86_32/mm.c @@ -27,6 +27,7 @@ #include #include #include +#include extern l1_pgentry_t *mapcache; @@ -184,6 +185,41 @@ void subarch_init_memory(struct domain *dom_xen) } } +long arch_memory_op(int op, void *arg) +{ + struct xen_machphys_mfn_list xmml; + unsigned long mfn; + unsigned int i, max; + long rc = 0; + + switch ( op ) + { + case XENMEM_machphys_mfn_list: + if ( copy_from_user(&xmml, arg, sizeof(xmml)) ) + return -EFAULT; + + max = min_t(unsigned int, xmml.max_extents, mpt_size >> 21); + + for ( i = 0; i < max; i++ ) + { + mfn = l2e_get_pfn(idle_pg_table_l2[l2_linear_offset( + RDWR_MPT_VIRT_START + (i << 21))]) + l1_table_offset(i << 21); + if ( put_user(mfn, &xmml.extent_start[i]) ) + return -EFAULT; + } + + if ( put_user(i, &((struct xen_machphys_mfn_list *)arg)->nr_extents) ) + return -EFAULT; + + break; + + default: + rc = -ENOSYS; + break; + } + + return rc; +} long do_stack_switch(unsigned long ss, unsigned long esp) { diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index a20c900fb0..a9e71746c6 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -28,6 +28,7 @@ #include #include #include +#include struct pfn_info *alloc_xen_pagetable(void) { @@ -174,6 +175,51 @@ void subarch_init_memory(struct domain *dom_xen) } } +long arch_memory_op(int op, void *arg) +{ + struct xen_machphys_mfn_list xmml; + l3_pgentry_t l3e; + l2_pgentry_t l2e; + unsigned long mfn, v; + unsigned int i; + long rc = 0; + + switch ( op ) + { + case XENMEM_machphys_mfn_list: + if ( copy_from_user(&xmml, arg, sizeof(xmml)) ) + return -EFAULT; + + for ( v = RDWR_MPT_VIRT_START; v != RDWR_MPT_VIRT_END; v += 1 << 21 ) + { + l3e = l4e_to_l3e(idle_pg_table[l4_table_offset(v)])[ + l3_table_offset(v)]; + if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) ) + break; + l2e = l3e_to_l2e(l3e)[l2_table_offset(v)]; + if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) ) + break; + mfn = l2e_get_pfn(l2e) + l1_table_offset(v); + if ( i == xmml.max_extents ) + break; + if ( put_user(mfn, &xmml.extent_start[i]) ) + return -EFAULT; + i++; + } + + if ( put_user(i, &((struct xen_machphys_mfn_list *)arg)->nr_extents) ) + return -EFAULT; + + break; + + default: + rc = -ENOSYS; + break; + } + + return rc; +} + long do_stack_switch(unsigned long ss, unsigned long esp) { if ( (ss & 3) != 3 ) diff --git a/xen/common/memory.c b/xen/common/memory.c index 79d6dca2e3..49a0802a50 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -215,7 +215,7 @@ long do_memory_op(int cmd, void *arg) break; default: - rc = -ENOSYS; + rc = arch_memory_op(op, arg); break; } diff --git a/xen/include/asm-ia64/mm.h b/xen/include/asm-ia64/mm.h index 8ab80ab5dc..e38ba4f149 100644 --- a/xen/include/asm-ia64/mm.h +++ b/xen/include/asm-ia64/mm.h @@ -440,4 +440,7 @@ extern unsigned long lookup_domain_mpa(struct domain *d, unsigned long mpaddr); #define __gpa_to_mpa(_d, gpa) \ ((__gpfn_to_mfn((_d),(gpa)>>PAGE_SHIFT)<