[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/7] add explicit parameter to macros instead of assuming symbol name available on the stack or as a global variable.
add explicit parameter to macros instead of assuming symbol name available on the stack or as a global variable. --- tools/libxc/xc_core.c | 2 +- tools/libxc/xc_core_x86.c | 20 +++++----- tools/libxc/xc_domain_restore.c | 66 +++++++++++++++--------------- tools/libxc/xc_domain_save.c | 84 +++++++++++++++++++------------------- tools/libxc/xc_offline_page.c | 8 ++-- tools/libxc/xc_resume.c | 12 +++--- tools/libxc/xg_private.h | 16 ++++---- tools/libxc/xg_save_restore.h | 22 +++++----- 8 files changed, 115 insertions(+), 115 deletions(-) diff --git a/tools/libxc/xc_core.c b/tools/libxc/xc_core.c index 0c226ac..c52212e 100644 --- a/tools/libxc/xc_core.c +++ b/tools/libxc/xc_core.c @@ -899,7 +899,7 @@ out: if ( memory_map != NULL ) free(memory_map); if ( p2m != NULL ) - munmap(p2m, PAGE_SIZE * P2M_FL_ENTRIES); + munmap(p2m, PAGE_SIZE * P2M_FL_ENTRIES(p2m_size, guest_width)); if ( p2m_array != NULL ) free(p2m_array); if ( pfn_array != NULL ) diff --git a/tools/libxc/xc_core_x86.c b/tools/libxc/xc_core_x86.c index fc2a7a1..2955af5 100644 --- a/tools/libxc/xc_core_x86.c +++ b/tools/libxc/xc_core_x86.c @@ -22,7 +22,7 @@ #include "xc_core.h" #include "xc_e820.h" -#define GET_FIELD(_p, _f) ((guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f)) +#define GET_FIELD(_gw, _p, _f) ((_gw==8) ? ((_p)->x64._f) : ((_p)->x32._f)) #ifndef MAX #define MAX(_a, _b) ((_a) >= (_b) ? (_a) : (_b)) @@ -101,7 +101,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, unsigned int guest_width, xc_dominfo_t *i live_p2m_frame_list_list = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, - GET_FIELD(live_shinfo, arch.pfn_to_mfn_frame_list_list)); + GET_FIELD(guest_width, live_shinfo, arch.pfn_to_mfn_frame_list_list)); if ( !live_p2m_frame_list_list ) { @@ -131,7 +131,7 @@ xc_core_arch_map_p2m_rw(int xc_handle, unsigned int guest_width, xc_dominfo_t *i live_p2m_frame_list = xc_map_foreign_pages(xc_handle, dom, PROT_READ, p2m_frame_list_list, - P2M_FLL_ENTRIES); + P2M_FLL_ENTRIES(p2m_size, guest_width)); if ( !live_p2m_frame_list ) { @@ -140,26 +140,26 @@ xc_core_arch_map_p2m_rw(int xc_handle, unsigned int guest_width, xc_dominfo_t *i } /* Get a local copy of the live_P2M_frame_list */ - if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) ) + if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE(p2m_size, guest_width))) ) { ERROR("Couldn't allocate p2m_frame_list array"); goto out; } - memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE); - memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE); + memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE(p2m_size, guest_width)); + memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE(p2m_size, guest_width)); /* Canonicalize guest's unsigned long vs ours */ if ( guest_width > sizeof(unsigned long) ) - for ( i = 0; i < P2M_FL_ENTRIES; i++ ) + for ( i = 0; i < P2M_FL_ENTRIES(p2m_size, guest_width); i++ ) p2m_frame_list[i] = ((uint64_t *)p2m_frame_list)[i]; else if ( guest_width < sizeof(unsigned long) ) - for ( i = P2M_FL_ENTRIES - 1; i >= 0; i-- ) + for ( i = P2M_FL_ENTRIES(p2m_size, guest_width) - 1; i >= 0; i-- ) p2m_frame_list[i] = ((uint32_t *)p2m_frame_list)[i]; *live_p2m = xc_map_foreign_pages(xc_handle, dom, rw ? (PROT_READ | PROT_WRITE) : PROT_READ, p2m_frame_list, - P2M_FL_ENTRIES); + P2M_FL_ENTRIES(p2m_size, guest_width)); if ( !*live_p2m ) { @@ -178,7 +178,7 @@ out: munmap(live_p2m_frame_list_list, PAGE_SIZE); if ( live_p2m_frame_list ) - munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(live_p2m_frame_list, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); if ( p2m_frame_list_list ) free(p2m_frame_list_list); diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c index 01d7924..e3d2d4a 100644 --- a/tools/libxc/xc_domain_restore.c +++ b/tools/libxc/xc_domain_restore.c @@ -525,7 +525,7 @@ static int uncanonicalize_pagetable(int xc_handle, uint32_t dom, if ( !(pte & _PAGE_PRESENT) ) continue; - pfn = (pte >> PAGE_SHIFT) & MFN_MASK_X86; + pfn = (pte >> PAGE_SHIFT) & MFN_MASK_X86(guest_width); /* Allocate mfn if necessary */ if ( p2m[pfn] == INVALID_P2M_ENTRY ) @@ -535,7 +535,7 @@ static int uncanonicalize_pagetable(int xc_handle, uint32_t dom, 1, &pfn, &force_pfn, superpages) != 0) return 0; } - pte &= ~MADDR_MASK_X86; + pte &= ~MADDR_MASK_X86(guest_width); pte |= (uint64_t)p2m[pfn] << PAGE_SHIFT; if ( pt_levels == 2 ) @@ -618,7 +618,7 @@ static xen_pfn_t *load_p2m_frame_list( tot_bytes -= chunk_bytes; chunk_bytes = 0; - if ( GET_FIELD(&ctxt, vm_assist) + if ( GET_FIELD(guest_width, &ctxt, vm_assist) & (1UL << VMASST_TYPE_pae_extended_cr3) ) *pae_extended_cr3 = 1; } @@ -651,7 +651,7 @@ static xen_pfn_t *load_p2m_frame_list( /* Now that we know the guest's word-size, can safely allocate * the p2m frame list */ - if ( (p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) == NULL ) + if ( (p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE(p2m_size, guest_width))) == NULL ) { ERROR("Couldn't allocate p2m_frame_list array"); return NULL; @@ -660,7 +660,7 @@ static xen_pfn_t *load_p2m_frame_list( /* First entry has already been read. */ p2m_frame_list[0] = p2m_fl_zero; if ( read_exact(io_fd, &p2m_frame_list[1], - (P2M_FL_ENTRIES - 1) * sizeof(xen_pfn_t)) ) + (P2M_FL_ENTRIES(p2m_size, guest_width) - 1) * sizeof(xen_pfn_t)) ) { ERROR("read p2m_frame_list failed"); return NULL; @@ -1787,7 +1787,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, DPRINTF("read VCPU %d\n", i); if ( !new_ctxt_format ) - SET_FIELD(&ctxt, flags, GET_FIELD(&ctxt, flags) | VGCF_online); + SET_FIELD(guest_width, &ctxt, flags, GET_FIELD(guest_width, &ctxt, flags) | VGCF_online); if ( i == 0 ) { @@ -1795,7 +1795,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, * Uncanonicalise the suspend-record frame number and poke * resume record. */ - pfn = GET_FIELD(&ctxt, user_regs.edx); + pfn = GET_FIELD(guest_width, &ctxt, user_regs.edx); if ( (pfn >= p2m_size) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB) ) { @@ -1803,30 +1803,30 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, goto out; } mfn = p2m[pfn]; - SET_FIELD(&ctxt, user_regs.edx, mfn); + SET_FIELD(guest_width, &ctxt, user_regs.edx, mfn); start_info = xc_map_foreign_range( xc_handle, dom, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn); - SET_FIELD(start_info, nr_pages, p2m_size); - SET_FIELD(start_info, shared_info, shared_info_frame<<PAGE_SHIFT); - SET_FIELD(start_info, flags, 0); - *store_mfn = p2m[GET_FIELD(start_info, store_mfn)]; - SET_FIELD(start_info, store_mfn, *store_mfn); - SET_FIELD(start_info, store_evtchn, store_evtchn); - *console_mfn = p2m[GET_FIELD(start_info, console.domU.mfn)]; - SET_FIELD(start_info, console.domU.mfn, *console_mfn); - SET_FIELD(start_info, console.domU.evtchn, console_evtchn); + SET_FIELD(guest_width, start_info, nr_pages, p2m_size); + SET_FIELD(guest_width, start_info, shared_info, shared_info_frame<<PAGE_SHIFT); + SET_FIELD(guest_width, start_info, flags, 0); + *store_mfn = p2m[GET_FIELD(guest_width, start_info, store_mfn)]; + SET_FIELD(guest_width, start_info, store_mfn, *store_mfn); + SET_FIELD(guest_width, start_info, store_evtchn, store_evtchn); + *console_mfn = p2m[GET_FIELD(guest_width, start_info, console.domU.mfn)]; + SET_FIELD(guest_width, start_info, console.domU.mfn, *console_mfn); + SET_FIELD(guest_width, start_info, console.domU.evtchn, console_evtchn); munmap(start_info, PAGE_SIZE); } /* Uncanonicalise each GDT frame number. */ - if ( GET_FIELD(&ctxt, gdt_ents) > 8192 ) + if ( GET_FIELD(guest_width, &ctxt, gdt_ents) > 8192 ) { ERROR("GDT entry count out of range"); goto out; } - for ( j = 0; (512*j) < GET_FIELD(&ctxt, gdt_ents); j++ ) + for ( j = 0; (512*j) < GET_FIELD(guest_width, &ctxt, gdt_ents); j++ ) { - pfn = GET_FIELD(&ctxt, gdt_frames[j]); + pfn = GET_FIELD(guest_width, &ctxt, gdt_frames[j]); if ( (pfn >= p2m_size) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB) ) { @@ -1834,10 +1834,10 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, j, (unsigned long)pfn); goto out; } - SET_FIELD(&ctxt, gdt_frames[j], p2m[pfn]); + SET_FIELD(guest_width, &ctxt, gdt_frames[j], p2m[pfn]); } /* Uncanonicalise the page table base pointer. */ - pfn = UNFOLD_CR3(GET_FIELD(&ctxt, ctrlreg[3])); + pfn = UNFOLD_CR3(guest_width, GET_FIELD(guest_width, &ctxt, ctrlreg[3])); if ( pfn >= p2m_size ) { @@ -1854,12 +1854,12 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT); goto out; } - SET_FIELD(&ctxt, ctrlreg[3], FOLD_CR3(p2m[pfn])); + SET_FIELD(guest_width, &ctxt, ctrlreg[3], FOLD_CR3(guest_width, p2m[pfn])); /* Guest pagetable (x86/64) stored in otherwise-unused CR1. */ if ( (pt_levels == 4) && (ctxt.x64.ctrlreg[1] & 1) ) { - pfn = UNFOLD_CR3(ctxt.x64.ctrlreg[1] & ~1); + pfn = UNFOLD_CR3(guest_width, ctxt.x64.ctrlreg[1] & ~1); if ( pfn >= p2m_size ) { ERROR("User PT base is bad: pfn=%lu p2m_size=%lu", @@ -1874,7 +1874,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, (unsigned long)pt_levels<<XEN_DOMCTL_PFINFO_LTAB_SHIFT); goto out; } - ctxt.x64.ctrlreg[1] = FOLD_CR3(p2m[pfn]); + ctxt.x64.ctrlreg[1] = FOLD_CR3(guest_width, p2m[pfn]); } domctl.cmd = XEN_DOMCTL_setvcpucontext; domctl.domain = (domid_t)dom; @@ -1910,22 +1910,22 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame); /* restore saved vcpu_info and arch specific info */ - MEMCPY_FIELD(new_shared_info, old_shared_info, vcpu_info); - MEMCPY_FIELD(new_shared_info, old_shared_info, arch); + MEMCPY_FIELD(guest_width, new_shared_info, old_shared_info, vcpu_info); + MEMCPY_FIELD(guest_width, new_shared_info, old_shared_info, arch); /* clear any pending events and the selector */ - MEMSET_ARRAY_FIELD(new_shared_info, evtchn_pending, 0); + MEMSET_ARRAY_FIELD(guest_width, new_shared_info, evtchn_pending, 0); for ( i = 0; i < XEN_LEGACY_MAX_VCPUS; i++ ) - SET_FIELD(new_shared_info, vcpu_info[i].evtchn_pending_sel, 0); + SET_FIELD(guest_width, new_shared_info, vcpu_info[i].evtchn_pending_sel, 0); /* mask event channels */ - MEMSET_ARRAY_FIELD(new_shared_info, evtchn_mask, 0xff); + MEMSET_ARRAY_FIELD(guest_width, new_shared_info, evtchn_mask, 0xff); /* leave wallclock time. set by hypervisor */ munmap(new_shared_info, PAGE_SIZE); /* Uncanonicalise the pfn-to-mfn table frame-number list. */ - for ( i = 0; i < P2M_FL_ENTRIES; i++ ) + for ( i = 0; i < P2M_FL_ENTRIES(p2m_size, guest_width); i++ ) { pfn = p2m_frame_list[i]; if ( (pfn >= p2m_size) || (pfn_type[pfn] != XEN_DOMCTL_PFINFO_NOTAB) ) @@ -1938,7 +1938,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, /* Copy the P2M we've constructed to the 'live' P2M */ if ( !(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE, - p2m_frame_list, P2M_FL_ENTRIES)) ) + p2m_frame_list, P2M_FL_ENTRIES(p2m_size, guest_width))) ) { ERROR("Couldn't map p2m table"); goto out; @@ -1954,7 +1954,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uint32_t dom, ((uint32_t *)live_p2m)[i] = p2m[i]; else memcpy(live_p2m, p2m, p2m_size * sizeof(xen_pfn_t)); - munmap(live_p2m, P2M_FL_ENTRIES * PAGE_SIZE); + munmap(live_p2m, P2M_FL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); DPRINTF("Domain ready to be built.\n"); rc = 0; diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c index 30c1b6d..697d93c 100644 --- a/tools/libxc/xc_domain_save.c +++ b/tools/libxc/xc_domain_save.c @@ -75,7 +75,7 @@ struct outbuf { * Returns TRUE if the given machine frame number has a unique mapping * in the guest's pseudophysical map. */ -#define MFN_IS_IN_PSEUDOPHYS_MAP(_mfn) \ +#define MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, _mfn) \ (((_mfn) < (max_mfn)) && \ ((mfn_to_pfn(_mfn) < (p2m_size)) && \ (pfn_to_mfn(mfn_to_pfn(_mfn)) == (_mfn)))) @@ -462,12 +462,12 @@ static void *map_frame_list_list(int xc_handle, uint32_t dom, { int count = 100; void *p; - uint64_t fll = GET_FIELD(shinfo, arch.pfn_to_mfn_frame_list_list); + uint64_t fll = GET_FIELD(guest_width, shinfo, arch.pfn_to_mfn_frame_list_list); while ( count-- && (fll == 0) ) { usleep(10000); - fll = GET_FIELD(shinfo, arch.pfn_to_mfn_frame_list_list); + fll = GET_FIELD(guest_width, shinfo, arch.pfn_to_mfn_frame_list_list); } if ( fll == 0 ) @@ -525,7 +525,7 @@ static int canonicalize_pagetable(unsigned long type, unsigned long pfn, hstart = (hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; he = ((const uint64_t *) spage)[hstart]; - if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) == m2p_mfn0 ) + if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86(guest_width)) == m2p_mfn0 ) { /* hvirt starts with xen stuff... */ xen_start = hstart; @@ -535,7 +535,7 @@ static int canonicalize_pagetable(unsigned long type, unsigned long pfn, /* old L2s from before hole was shrunk... */ hstart = (0xf5800000 >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; he = ((const uint64_t *) spage)[hstart]; - if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) == m2p_mfn0 ) + if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86(guest_width)) == m2p_mfn0 ) xen_start = hstart; } } @@ -565,8 +565,8 @@ static int canonicalize_pagetable(unsigned long type, unsigned long pfn, if ( pte & _PAGE_PRESENT ) { - mfn = (pte >> PAGE_SHIFT) & MFN_MASK_X86; - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) ) + mfn = (pte >> PAGE_SHIFT) & MFN_MASK_X86(guest_width); + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, mfn) ) { /* This will happen if the type info is stale which is quite feasible under live migration */ @@ -582,7 +582,7 @@ static int canonicalize_pagetable(unsigned long type, unsigned long pfn, else pfn = mfn_to_pfn(mfn); - pte &= ~MADDR_MASK_X86; + pte &= ~MADDR_MASK_X86(guest_width); pte |= (uint64_t)pfn << PAGE_SHIFT; /* @@ -718,7 +718,7 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, live_p2m_frame_list = xc_map_foreign_batch(xc_handle, dom, PROT_READ, p2m_frame_list_list, - P2M_FLL_ENTRIES); + P2M_FLL_ENTRIES(p2m_size, guest_width)); if ( !live_p2m_frame_list ) { ERROR("Couldn't map p2m_frame_list"); @@ -726,20 +726,20 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, } /* Get a local copy of the live_P2M_frame_list */ - if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE)) ) + if ( !(p2m_frame_list = malloc(P2M_TOOLS_FL_SIZE(p2m_size, guest_width))) ) { ERROR("Couldn't allocate p2m_frame_list array"); goto out; } - memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE); - memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE); + memset(p2m_frame_list, 0, P2M_TOOLS_FL_SIZE(p2m_size, guest_width)); + memcpy(p2m_frame_list, live_p2m_frame_list, P2M_GUEST_FL_SIZE(p2m_size, guest_width)); /* Canonicalize guest's unsigned long vs ours */ if ( guest_width > sizeof(unsigned long) ) - for ( i = 0; i < P2M_FL_ENTRIES; i++ ) + for ( i = 0; i < P2M_FL_ENTRIES(p2m_size, guest_width); i++ ) p2m_frame_list[i] = ((uint64_t *)p2m_frame_list)[i]; else if ( guest_width < sizeof(unsigned long) ) - for ( i = P2M_FL_ENTRIES - 1; i >= 0; i-- ) + for ( i = P2M_FL_ENTRIES(p2m_size, guest_width) - 1; i >= 0; i-- ) p2m_frame_list[i] = ((uint32_t *)p2m_frame_list)[i]; @@ -750,7 +750,7 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, p2m = xc_map_foreign_batch(xc_handle, dom, PROT_READ, p2m_frame_list, - P2M_FL_ENTRIES); + P2M_FL_ENTRIES(p2m_size, guest_width)); if ( !p2m ) { ERROR("Couldn't map p2m table"); @@ -759,26 +759,26 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, live_p2m = p2m; /* So that translation macros will work */ /* Canonicalise the pfn-to-mfn table frame-number list. */ - for ( i = 0; i < p2m_size; i += FPP ) + for ( i = 0; i < p2m_size; i += FPP(guest_width) ) { - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(p2m_frame_list[i/FPP]) ) + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, p2m_frame_list[i/FPP(guest_width)]) ) { ERROR("Frame# in pfn-to-mfn frame list is not in pseudophys"); ERROR("entry %d: p2m_frame_list[%ld] is 0x%"PRIx64", max 0x%lx", - i, i/FPP, (uint64_t)p2m_frame_list[i/FPP], max_mfn); - if ( p2m_frame_list[i/FPP] < max_mfn ) + i, i/FPP(guest_width), (uint64_t)p2m_frame_list[i/FPP(guest_width)], max_mfn); + if ( p2m_frame_list[i/FPP(guest_width)] < max_mfn ) { ERROR("m2p[0x%"PRIx64"] = 0x%"PRIx64, - (uint64_t)p2m_frame_list[i/FPP], - (uint64_t)live_m2p[p2m_frame_list[i/FPP]]); + (uint64_t)p2m_frame_list[i/FPP(guest_width)], + (uint64_t)live_m2p[p2m_frame_list[i/FPP(guest_width)]]); ERROR("p2m[0x%"PRIx64"] = 0x%"PRIx64, - (uint64_t)live_m2p[p2m_frame_list[i/FPP]], - (uint64_t)p2m[live_m2p[p2m_frame_list[i/FPP]]]); + (uint64_t)live_m2p[p2m_frame_list[i/FPP(guest_width)]], + (uint64_t)p2m[live_m2p[p2m_frame_list[i/FPP(guest_width)]]]); } goto out; } - p2m_frame_list[i/FPP] = mfn_to_pfn(p2m_frame_list[i/FPP]); + p2m_frame_list[i/FPP(guest_width)] = mfn_to_pfn(p2m_frame_list[i/FPP(guest_width)]); } if ( xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt) ) @@ -813,7 +813,7 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, } if ( write_exact(io_fd, p2m_frame_list, - P2M_FL_ENTRIES * sizeof(xen_pfn_t)) ) + P2M_FL_ENTRIES(p2m_size, guest_width) * sizeof(xen_pfn_t)) ) { PERROR("write: p2m_frame_list"); goto out; @@ -824,13 +824,13 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handle, out: if ( !success && p2m ) - munmap(p2m, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(p2m, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); if ( live_p2m_frame_list_list ) munmap(live_p2m_frame_list_list, PAGE_SIZE); if ( live_p2m_frame_list ) - munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(live_p2m_frame_list, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); if ( p2m_frame_list_list ) free(p2m_frame_list_list); @@ -1632,13 +1632,13 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, } /* Canonicalise the suspend-record frame number. */ - mfn = GET_FIELD(&ctxt, user_regs.edx); - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) ) + mfn = GET_FIELD(guest_width, &ctxt, user_regs.edx); + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, mfn) ) { ERROR("Suspend record is not in range of pseudophys map"); goto out; } - SET_FIELD(&ctxt, user_regs.edx, mfn_to_pfn(mfn)); + SET_FIELD(guest_width, &ctxt, user_regs.edx, mfn_to_pfn(mfn)); for ( i = 0; i <= info.max_vcpu_id; i++ ) { @@ -1652,38 +1652,38 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, } /* Canonicalise each GDT frame number. */ - for ( j = 0; (512*j) < GET_FIELD(&ctxt, gdt_ents); j++ ) + for ( j = 0; (512*j) < GET_FIELD(guest_width, &ctxt, gdt_ents); j++ ) { - mfn = GET_FIELD(&ctxt, gdt_frames[j]); - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(mfn) ) + mfn = GET_FIELD(guest_width, &ctxt, gdt_frames[j]); + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, mfn) ) { ERROR("GDT frame is not in range of pseudophys map"); goto out; } - SET_FIELD(&ctxt, gdt_frames[j], mfn_to_pfn(mfn)); + SET_FIELD(guest_width, &ctxt, gdt_frames[j], mfn_to_pfn(mfn)); } /* Canonicalise the page table base pointer. */ - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3( - GET_FIELD(&ctxt, ctrlreg[3]))) ) + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, UNFOLD_CR3(guest_width, + GET_FIELD(guest_width, &ctxt, ctrlreg[3]))) ) { ERROR("PT base is not in range of pseudophys map"); goto out; } - SET_FIELD(&ctxt, ctrlreg[3], - FOLD_CR3(mfn_to_pfn(UNFOLD_CR3(GET_FIELD(&ctxt, ctrlreg[3]))))); + SET_FIELD(guest_width, &ctxt, ctrlreg[3], + FOLD_CR3(guest_width, mfn_to_pfn(UNFOLD_CR3(guest_width, GET_FIELD(guest_width, &ctxt, ctrlreg[3]))))); /* Guest pagetable (x86/64) stored in otherwise-unused CR1. */ if ( (pt_levels == 4) && ctxt.x64.ctrlreg[1] ) { - if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(ctxt.x64.ctrlreg[1])) ) + if ( !MFN_IS_IN_PSEUDOPHYS_MAP(max_mfn, UNFOLD_CR3(guest_width, ctxt.x64.ctrlreg[1])) ) { ERROR("PT base is not in range of pseudophys map"); goto out; } /* Least-significant bit means 'valid PFN'. */ ctxt.x64.ctrlreg[1] = 1 | - FOLD_CR3(mfn_to_pfn(UNFOLD_CR3(ctxt.x64.ctrlreg[1]))); + FOLD_CR3(guest_width, mfn_to_pfn(UNFOLD_CR3(guest_width, ctxt.x64.ctrlreg[1]))); } if ( write_exact(io_fd, &ctxt, ((guest_width==8) @@ -1713,7 +1713,7 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, * Reset the MFN to be a known-invalid value. See map_frame_list_list(). */ memcpy(page, live_shinfo, PAGE_SIZE); - SET_FIELD(((shared_info_any_t *)page), + SET_FIELD(guest_width, ((shared_info_any_t *)page), arch.pfn_to_mfn_frame_list_list, 0); if ( write_exact(io_fd, page, PAGE_SIZE) ) { @@ -1783,7 +1783,7 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, munmap(live_shinfo, PAGE_SIZE); if ( live_p2m ) - munmap(live_p2m, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(live_p2m, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); if ( live_m2p ) munmap(live_m2p, M2P_SIZE(max_mfn)); diff --git a/tools/libxc/xc_offline_page.c b/tools/libxc/xc_offline_page.c index c386d88..7d25ec0 100644 --- a/tools/libxc/xc_offline_page.c +++ b/tools/libxc/xc_offline_page.c @@ -210,7 +210,7 @@ static int close_mem_info(int xc_handle, struct domain_mem_info *minfo) if (minfo->pfn_type) free(minfo->pfn_type); munmap(minfo->m2p_table, M2P_SIZE(minfo->max_mfn)); - munmap(minfo->p2m_table, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(minfo->p2m_table, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); minfo->p2m_table = minfo->m2p_table = NULL; return 0; @@ -307,7 +307,7 @@ failed: if (live_shinfo) munmap(live_shinfo, PAGE_SIZE); munmap(minfo->m2p_table, M2P_SIZE(minfo->max_mfn)); - munmap(minfo->p2m_table, P2M_FLL_ENTRIES * PAGE_SIZE); + munmap(minfo->p2m_table, P2M_FLL_ENTRIES(p2m_size, guest_width) * PAGE_SIZE); minfo->p2m_table = minfo->m2p_table = NULL; return -1; @@ -360,7 +360,7 @@ static int __clear_pte(uint64_t pte, uint64_t *new_pte, /* XXX Check for PSE bit here */ /* Hit one entry */ - if ( ((pte >> PAGE_SHIFT_X86) & MFN_MASK_X86) == mfn) + if ( ((pte >> PAGE_SHIFT_X86) & MFN_MASK_X86(guest_width)) == mfn) { *new_pte = pte & ~_PAGE_PRESENT; if (!backup_ptes(table_mfn, table_offset, backup)) @@ -389,7 +389,7 @@ static int __update_pte(uint64_t pte, uint64_t *new_pte, { if (pte & _PAGE_PRESENT) ERROR("Page present while in backup ptes\n"); - pte &= ~MFN_MASK_X86; + pte &= ~MFN_MASK_X86(guest_width); pte |= (new_mfn << PAGE_SHIFT_X86) | _PAGE_PRESENT; *new_pte = pte; return 1; diff --git a/tools/libxc/xc_resume.c b/tools/libxc/xc_resume.c index ad0f137..68e4f43 100644 --- a/tools/libxc/xc_resume.c +++ b/tools/libxc/xc_resume.c @@ -61,7 +61,7 @@ static int modify_returncode(int xc_handle, uint32_t domid) if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt)) != 0 ) return rc; - SET_FIELD(&ctxt, user_regs.eax, 1); + SET_FIELD(guest_width, &ctxt, user_regs.eax, 1); if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt)) != 0 ) return rc; @@ -157,7 +157,7 @@ static int xc_domain_resume_any(int xc_handle, uint32_t domid) p2m_frame_list = xc_map_foreign_batch(xc_handle, domid, PROT_READ, p2m_frame_list_list, - P2M_FLL_ENTRIES); + P2M_FLL_ENTRIES(p2m_size, guest_width)); if ( p2m_frame_list == NULL ) { ERROR("Couldn't map p2m_frame_list"); @@ -170,7 +170,7 @@ static int xc_domain_resume_any(int xc_handle, uint32_t domid) from a safety POV anyhow. */ p2m = xc_map_foreign_batch(xc_handle, domid, PROT_READ, p2m_frame_list, - P2M_FL_ENTRIES); + P2M_FL_ENTRIES(p2m_size, guest_width)); if ( p2m == NULL ) { ERROR("Couldn't map p2m table"); @@ -189,7 +189,7 @@ static int xc_domain_resume_any(int xc_handle, uint32_t domid) goto out; } - mfn = GET_FIELD(&ctxt, user_regs.edx); + mfn = GET_FIELD(guest_width, &ctxt, user_regs.edx); start_info = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE, PROT_READ | PROT_WRITE, mfn); @@ -218,9 +218,9 @@ static int xc_domain_resume_any(int xc_handle, uint32_t domid) out: unlock_pages((void *)&ctxt, sizeof ctxt); if (p2m) - munmap(p2m, P2M_FL_ENTRIES*PAGE_SIZE); + munmap(p2m, P2M_FL_ENTRIES(p2m_size, guest_width) *PAGE_SIZE); if (p2m_frame_list) - munmap(p2m_frame_list, P2M_FLL_ENTRIES*PAGE_SIZE); + munmap(p2m_frame_list, P2M_FLL_ENTRIES(p2m_size, guest_width) *PAGE_SIZE); if (p2m_frame_list_list) munmap(p2m_frame_list_list, PAGE_SIZE); if (shinfo) diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h index 1e74509..d86ef46 100644 --- a/tools/libxc/xg_private.h +++ b/tools/libxc/xg_private.h @@ -146,23 +146,23 @@ typedef l4_pgentry_64_t l4_pgentry_t; /* Number of xen_pfn_t in a page */ -#define FPP (PAGE_SIZE/(guest_width)) +#define FPP(guest_width) (PAGE_SIZE/(guest_width)) /* Number of entries in the pfn_to_mfn_frame_list_list */ -#define P2M_FLL_ENTRIES (((p2m_size)+(FPP*FPP)-1)/(FPP*FPP)) +#define P2M_FLL_ENTRIES(p2m_size, gw) (((p2m_size)+(FPP(gw) * FPP(gw))-1)/(FPP(gw) * FPP(gw))) /* Number of entries in the pfn_to_mfn_frame_list */ -#define P2M_FL_ENTRIES (((p2m_size)+FPP-1)/FPP) +#define P2M_FL_ENTRIES(p2m_size, gw) (((p2m_size)+ FPP(gw) -1)/ FPP(gw)) /* Size in bytes of the pfn_to_mfn_frame_list */ -#define P2M_GUEST_FL_SIZE ((P2M_FL_ENTRIES) * (guest_width)) -#define P2M_TOOLS_FL_SIZE ((P2M_FL_ENTRIES) * \ +#define P2M_GUEST_FL_SIZE(p2m_size, guest_width) ((P2M_FL_ENTRIES(p2m_size, guest_width)) * (guest_width)) +#define P2M_TOOLS_FL_SIZE(p2m_size, guest_width) ((P2M_FL_ENTRIES(p2m_size, guest_width)) * \ MAX((sizeof (xen_pfn_t)), guest_width)) /* Masks for PTE<->PFN conversions */ -#define MADDR_BITS_X86 ((guest_width == 8) ? 52 : 44) -#define MFN_MASK_X86 ((1ULL << (MADDR_BITS_X86 - PAGE_SHIFT_X86)) - 1) -#define MADDR_MASK_X86 (MFN_MASK_X86 << PAGE_SHIFT_X86) +#define MADDR_BITS_X86(guest_width) ((guest_width == 8) ? 52 : 44) +#define MFN_MASK_X86(gw) ((1ULL << (MADDR_BITS_X86(gw) - PAGE_SHIFT_X86)) - 1) +#define MADDR_MASK_X86(gw) (MFN_MASK_X86(gw) << PAGE_SHIFT_X86) #define PAEKERN_no 0 diff --git a/tools/libxc/xg_save_restore.h b/tools/libxc/xg_save_restore.h index 5d39982..6f16399 100644 --- a/tools/libxc/xg_save_restore.h +++ b/tools/libxc/xg_save_restore.h @@ -112,34 +112,34 @@ static inline int get_platform_info(int xc_handle, uint32_t dom, #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL)) -#define GET_FIELD(_p, _f) ((guest_width==8) ? ((_p)->x64._f) : ((_p)->x32._f)) +#define GET_FIELD(_gw, _p, _f) (((_gw)==8) ? ((_p)->x64._f) : ((_p)->x32._f)) -#define SET_FIELD(_p, _f, _v) do { \ - if (guest_width == 8) \ +#define SET_FIELD(_gw, _p, _f, _v) do { \ + if ((_gw) == 8) \ (_p)->x64._f = (_v); \ else \ (_p)->x32._f = (_v); \ } while (0) -#define UNFOLD_CR3(_c) \ - ((uint64_t)((guest_width == 8) \ +#define UNFOLD_CR3(_gw, _c) \ + ((uint64_t)(((_gw) == 8) \ ? ((_c) >> 12) \ : (((uint32_t)(_c) >> 12) | ((uint32_t)(_c) << 20)))) -#define FOLD_CR3(_c) \ - ((uint64_t)((guest_width == 8) \ +#define FOLD_CR3(_gw, _c) \ + ((uint64_t)(((_gw) == 8) \ ? ((uint64_t)(_c)) << 12 \ : (((uint32_t)(_c) << 12) | ((uint32_t)(_c) >> 20)))) -#define MEMCPY_FIELD(_d, _s, _f) do { \ - if (guest_width == 8) \ +#define MEMCPY_FIELD(_gw, _d, _s, _f) do { \ + if ((_gw) == 8) \ memcpy(&(_d)->x64._f, &(_s)->x64._f,sizeof((_d)->x64._f)); \ else \ memcpy(&(_d)->x32._f, &(_s)->x32._f,sizeof((_d)->x32._f)); \ } while (0) -#define MEMSET_ARRAY_FIELD(_p, _f, _v) do { \ - if (guest_width == 8) \ +#define MEMSET_ARRAY_FIELD(_gw, _p, _f, _v) do { \ + if ((_gw) == 8) \ memset(&(_p)->x64._f[0], (_v), sizeof((_p)->x64._f)); \ else \ memset(&(_p)->x32._f[0], (_v), sizeof((_p)->x32._f)); \ -- 1.6.5.2 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |