From: Vincent Hanquez Subject: [PATCH 2/7] create a global context structure to record global variables in save Date: Tue, 1 Dec 2009 06:59:09 +0000 Message-ID: <1259650754-15971-3-git-send-email-vincent.hanquez@eu.citrix.com> References: <1259650754-15971-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.5.2" Return-path: In-Reply-To: <1259650754-15971-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Xen Devel Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.5.2 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable Signed-off-by: Vincent Hanquez --- tools/libxc/xc_domain_save.c | 96 ++++++++++++++++++++----------------= ----- 1 files changed, 47 insertions(+), 49 deletions(-) --------------1.6.5.2 Content-Type: text/x-patch; name="0002-create-a-global-context-structure-to-record-global-v.patch" Content-Disposition: attachment; filename="0002-create-a-global-context-structure-to-record-global-v.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c index 10679af..0423aba 100644 --- a/tools/libxc/xc_domain_save.c +++ b/tools/libxc/xc_domain_save.c @@ -30,26 +30,24 @@ #define DEF_MAX_ITERS 29 /* limit us to 30 times round loop */ #define DEF_MAX_FACTOR 3 /* never send more than 3x p2m_size */ =20 -/* max mfn of the whole machine */ -static unsigned long max_mfn; - -/* virtual starting address of the hypervisor */ -static unsigned long hvirt_start; - -/* #levels of page tables used by the current guest */ -static unsigned int pt_levels; - - -/* Live mapping of the table mapping each PFN to its current MFN. */ -static xen_pfn_t *live_p2m =3D NULL; - -/* Live mapping of system MFN to PFN table. */ -static xen_pfn_t *live_m2p =3D NULL; -static unsigned long m2p_mfn0; +struct save_context { + unsigned long hvirt_start; /* virtual starting address of the hyperv= isor */ + unsigned int pt_levels; /* #levels of page tables used by the curren= t guest */ + unsigned long max_mfn; /* max mfn of the whole machine */ + xen_pfn_t *live_p2m; /* Live mapping of the table mapping each PFN t= o its current MFN. */ + xen_pfn_t *live_m2p; /* Live mapping of system MFN to PFN table. */ + unsigned long m2p_mfn0; +}; =20 static struct domain_info_context _dinfo; static struct domain_info_context *dinfo =3D &_dinfo; =20 +static struct save_context _ctx =3D { + .live_p2m =3D NULL, + .live_m2p =3D NULL, +}; +static struct save_context *ctx =3D &_ctx; + /* buffer for output */ struct outbuf { void* buf; @@ -61,20 +59,20 @@ struct outbuf { =20 /* grep fodder: machine_to_phys */ =20 -#define mfn_to_pfn(_mfn) (live_m2p[(_mfn)]) +#define mfn_to_pfn(_mfn) (ctx->live_m2p[(_mfn)]) =20 #define pfn_to_mfn(_pfn) \ ((xen_pfn_t) ((dinfo->guest_width=3D=3D8) = \ - ? (((uint64_t *)live_p2m)[(_pfn)]) \ - : ((((uint32_t *)live_p2m)[(_pfn)]) =3D=3D 0xffffffffU = \ - ? (-1UL) : (((uint32_t *)live_p2m)[(_pfn)])))) + ? (((uint64_t *)ctx->live_p2m)[(_pfn)]) = \ + : ((((uint32_t *)ctx->live_p2m)[(_pfn)]) =3D=3D 0xffffff= ffU \ + ? (-1UL) : (((uint32_t *)ctx->live_p2m)[(_pfn)])))) =20 /* * 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) \ - (((_mfn) < (max_mfn)) && \ + (((_mfn) < (ctx->max_mfn)) && \ ((mfn_to_pfn(_mfn) < (dinfo->p2m_size)) && \ (pfn_to_mfn(mfn_to_pfn(_mfn)) =3D=3D (_mfn)))) =20 @@ -502,12 +500,12 @@ static int canonicalize_pagetable(unsigned long typ= e, unsigned long pfn, ** reserved hypervisor mappings. This depends on the current ** page table type as well as the number of paging levels. */ - xen_start =3D xen_end =3D pte_last =3D PAGE_SIZE / ((pt_levels =3D=3D= 2) ? 4 : 8); + xen_start =3D xen_end =3D pte_last =3D PAGE_SIZE / ((ctx->pt_levels = =3D=3D 2) ? 4 : 8); =20 - if ( (pt_levels =3D=3D 2) && (type =3D=3D XEN_DOMCTL_PFINFO_L2TAB) ) - xen_start =3D (hvirt_start >> L2_PAGETABLE_SHIFT); + if ( (ctx->pt_levels =3D=3D 2) && (type =3D=3D XEN_DOMCTL_PFINFO_L2T= AB) ) + xen_start =3D (ctx->hvirt_start >> L2_PAGETABLE_SHIFT); =20 - if ( (pt_levels =3D=3D 3) && (type =3D=3D XEN_DOMCTL_PFINFO_L3TAB) ) + if ( (ctx->pt_levels =3D=3D 3) && (type =3D=3D XEN_DOMCTL_PFINFO_L3T= AB) ) xen_start =3D L3_PAGETABLE_ENTRIES_PAE; =20 /* @@ -515,30 +513,30 @@ static int canonicalize_pagetable(unsigned long typ= e, unsigned long pfn, ** We can spot this by looking for the guest's mappingof the m2p. ** Guests must ensure that this check will fail for other L2s. */ - if ( (pt_levels =3D=3D 3) && (type =3D=3D XEN_DOMCTL_PFINFO_L2TAB) ) + if ( (ctx->pt_levels =3D=3D 3) && (type =3D=3D XEN_DOMCTL_PFINFO_L2T= AB) ) { int hstart; uint64_t he; =20 - hstart =3D (hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; + hstart =3D (ctx->hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; he =3D ((const uint64_t *) spage)[hstart]; =20 - if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) =3D=3D m2p_mfn0 ) + if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) =3D=3D ctx->m2p_mfn0 ) { /* hvirt starts with xen stuff... */ xen_start =3D hstart; } - else if ( hvirt_start !=3D 0xf5800000 ) + else if ( ctx->hvirt_start !=3D 0xf5800000 ) { /* old L2s from before hole was shrunk... */ hstart =3D (0xf5800000 >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; he =3D ((const uint64_t *) spage)[hstart]; - if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) =3D=3D m2p_mfn0 ) + if ( ((he >> PAGE_SHIFT) & MFN_MASK_X86) =3D=3D ctx->m2p_mfn= 0 ) xen_start =3D hstart; } } =20 - if ( (pt_levels =3D=3D 4) && (type =3D=3D XEN_DOMCTL_PFINFO_L4TAB) ) + if ( (ctx->pt_levels =3D=3D 4) && (type =3D=3D XEN_DOMCTL_PFINFO_L4T= AB) ) { /* ** XXX SMH: should compute these from hvirt_start (which we have= ) @@ -553,7 +551,7 @@ static int canonicalize_pagetable(unsigned long type,= unsigned long pfn, { unsigned long pfn, mfn; =20 - if ( pt_levels =3D=3D 2 ) + if ( ctx->pt_levels =3D=3D 2 ) pte =3D ((const uint32_t*)spage)[i]; else pte =3D ((const uint64_t*)spage)[i]; @@ -588,13 +586,13 @@ static int canonicalize_pagetable(unsigned long typ= e, unsigned long pfn, * a 64bit hypervisor. We zap these here to avoid any * surprise at restore time... */ - if ( (pt_levels =3D=3D 3) && + if ( (ctx->pt_levels =3D=3D 3) && (type =3D=3D XEN_DOMCTL_PFINFO_L3TAB) && (pte & (_PAGE_USER|_PAGE_RW|_PAGE_ACCESSED)) ) pte &=3D ~(_PAGE_USER|_PAGE_RW|_PAGE_ACCESSED); } =20 - if ( pt_levels =3D=3D 2 ) + if ( ctx->pt_levels =3D=3D 2 ) ((uint32_t*)dpage)[i] =3D pte; else ((uint64_t*)dpage)[i] =3D pte; @@ -753,7 +751,7 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_handl= e, ERROR("Couldn't map p2m table"); goto out; } - live_p2m =3D p2m; /* So that translation macros will work */ + ctx->live_p2m =3D p2m; /* So that translation macros will work */ =20 /* Canonicalise the pfn-to-mfn table frame-number list. */ for ( i =3D 0; i < dinfo->p2m_size; i +=3D FPP ) @@ -762,15 +760,15 @@ static xen_pfn_t *map_and_save_p2m_table(int xc_han= dle, { 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 )=20 + i, i/FPP, (uint64_t)p2m_frame_list[i/FPP], ctx->max_mf= n); + if ( p2m_frame_list[i/FPP] < ctx->max_mfn )=20 { ERROR("m2p[0x%"PRIx64"] =3D 0x%"PRIx64,=20 (uint64_t)p2m_frame_list[i/FPP], - (uint64_t)live_m2p[p2m_frame_list[i/FPP]]); + (uint64_t)ctx->live_m2p[p2m_frame_list[i/FPP]]); ERROR("p2m[0x%"PRIx64"] =3D 0x%"PRIx64,=20 - (uint64_t)live_m2p[p2m_frame_list[i/FPP]], - (uint64_t)p2m[live_m2p[p2m_frame_list[i/FPP]]]); + (uint64_t)ctx->live_m2p[p2m_frame_list[i/FPP]], + (uint64_t)p2m[ctx->live_m2p[p2m_frame_list[i/FPP]]= ]); =20 } goto out; @@ -924,7 +922,7 @@ int xc_domain_save(int xc_handle, int io_fd, uint32_t= dom, uint32_t max_iters, initialize_mbit_rate(); =20 if ( !get_platform_info(xc_handle, dom, - &max_mfn, &hvirt_start, &pt_levels, &dinfo->= guest_width) ) + &ctx->max_mfn, &ctx->hvirt_start, &ctx->pt_l= evels, &dinfo->guest_width) ) { ERROR("Unable to get platform info."); return 1; @@ -1063,7 +1061,7 @@ int xc_domain_save(int xc_handle, int io_fd, uint32= _t dom, uint32_t max_iters, } =20 /* Setup the mfn_to_pfn table mapping */ - if ( !(live_m2p =3D xc_map_m2p(xc_handle, max_mfn, PROT_READ, &m2p_m= fn0)) ) + if ( !(ctx->live_m2p =3D xc_map_m2p(xc_handle, ctx->max_mfn, PROT_RE= AD, &ctx->m2p_mfn0)) ) { ERROR("Failed to map live M2P table"); goto out; @@ -1081,8 +1079,8 @@ int xc_domain_save(int xc_handle, int io_fd, uint32= _t dom, uint32_t max_iters, int err =3D 0; =20 /* Map the P2M table, and write the list of P2M frames */ - live_p2m =3D map_and_save_p2m_table(xc_handle, io_fd, dom, live_= shinfo); - if ( live_p2m =3D=3D NULL ) + ctx->live_p2m =3D map_and_save_p2m_table(xc_handle, io_fd, dom, = live_shinfo); + if ( ctx->live_p2m =3D=3D NULL ) { ERROR("Failed to map/save the p2m frame list"); goto out; @@ -1701,7 +1699,7 @@ int xc_domain_save(int xc_handle, int io_fd, uint32= _t dom, uint32_t max_iters, FOLD_CR3(mfn_to_pfn(UNFOLD_CR3(GET_FIELD(&ctxt, ctrlreg[3]))= ))); =20 /* Guest pagetable (x86/64) stored in otherwise-unused CR1. */ - if ( (pt_levels =3D=3D 4) && ctxt.x64.ctrlreg[1] ) + if ( (ctx->pt_levels =3D=3D 4) && ctxt.x64.ctrlreg[1] ) { if ( !MFN_IS_IN_PSEUDOPHYS_MAP(UNFOLD_CR3(ctxt.x64.ctrlreg[1= ])) ) { @@ -1809,11 +1807,11 @@ int xc_domain_save(int xc_handle, int io_fd, uint= 32_t dom, uint32_t max_iters, if ( live_shinfo ) munmap(live_shinfo, PAGE_SIZE); =20 - if ( live_p2m ) - munmap(live_p2m, P2M_FLL_ENTRIES * PAGE_SIZE); + if ( ctx->live_p2m ) + munmap(ctx->live_p2m, P2M_FLL_ENTRIES * PAGE_SIZE); =20 - if ( live_m2p ) - munmap(live_m2p, M2P_SIZE(max_mfn)); + if ( ctx->live_m2p ) + munmap(ctx->live_m2p, M2P_SIZE(ctx->max_mfn)); =20 free(pfn_type); free(pfn_batch); --------------1.6.5.2 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.5.2--