From: Vincent Hanquez Subject: [PATCH 7/7] pass the restore_context through function and allocate the context on the restore function stack. Date: Tue, 1 Dec 2009 06:59:14 +0000 Message-ID: <1259650754-15971-8-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_restore.c | 62 ++++++++++++++++++++-------------= ------ 1 files changed, 32 insertions(+), 30 deletions(-) --------------1.6.5.2 Content-Type: text/x-patch; name="0007-pass-the-restore_context-through-function-and-alloca.patch" Content-Disposition: attachment; filename="0007-pass-the-restore_context-through-function-and-alloca.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_rest= ore.c index f178b00..827ba6b 100644 --- a/tools/libxc/xc_domain_restore.c +++ b/tools/libxc/xc_domain_restore.c @@ -43,13 +43,6 @@ struct restore_ctx { struct domain_info_context dinfo; }; =20 -static struct restore_ctx _ctx =3D { - .live_p2m =3D NULL, - .p2m =3D NULL, - .no_superpage_mem =3D 0, -}; -static struct restore_ctx *ctx =3D &_ctx; - /* ** ** @@ -69,7 +62,7 @@ static struct restore_ctx *ctx =3D &_ctx; #define SUPER_PAGE_TRACKING(pfn) ( (pfn) !=3D INVALID_SUPER_PAGE ) #define SUPER_PAGE_DONE(pfn) ( SUPER_PAGE_START(pfn) ) =20 -static int super_page_populated(unsigned long pfn) +static int super_page_populated(struct restore_ctx *ctx, unsigned long p= fn) { int i; pfn &=3D ~(SUPERPAGE_NR_PFNS - 1); @@ -87,6 +80,7 @@ static int super_page_populated(unsigned long pfn) */ static int break_super_page(int xc_handle, uint32_t dom, + struct restore_ctx *ctx, xen_pfn_t next_pfn) { xen_pfn_t *page_array, start_pfn, mfn; @@ -200,6 +194,7 @@ out: */ static int allocate_mfn_list(int xc_handle, uint32_t dom, + struct restore_ctx *ctx, unsigned long nr_extents, xen_pfn_t *batch_buf, xen_pfn_t *next_pfn, @@ -226,7 +221,7 @@ static int allocate_mfn_list(int xc_handle, !SUPER_PAGE_DONE(sp_pfn)) { /* break previously allocated super page*/ - if ( break_super_page(xc_handle, dom, sp_pfn) !=3D 0 ) + if ( break_super_page(xc_handle, dom, ctx, sp_pfn) !=3D 0 ) { ERROR("Break previous super page fail!\n"); return 1; @@ -249,7 +244,7 @@ static int allocate_mfn_list(int xc_handle, goto normal_page; =20 pfn =3D batch_buf[0] & ~XEN_DOMCTL_PFINFO_LTAB_MASK; - if ( super_page_populated(pfn) ) + if ( super_page_populated(ctx, pfn) ) goto normal_page; =20 pfn &=3D ~(SUPERPAGE_NR_PFNS - 1); @@ -300,6 +295,7 @@ normal_page: } =20 static int allocate_physmem(int xc_handle, uint32_t dom, + struct restore_ctx *ctx, unsigned long *region_pfn_type, int region_s= ize, unsigned int hvm, xen_pfn_t *region_mfn, int= superpages) { @@ -341,7 +337,7 @@ static int allocate_physmem(int xc_handle, uint32_t d= om, if ( SUPER_PAGE_START(pfn) ) { /* Start of a 2M extent, populate previsous buf */ - if ( allocate_mfn_list(xc_handle, dom, + if ( allocate_mfn_list(xc_handle, dom, ctx, batch_buf_len, batch_buf, &required_pfn, superpages) !=3D 0 ) { @@ -363,7 +359,7 @@ static int allocate_physmem(int xc_handle, uint32_t d= om, else if ( SUPER_PAGE_TRACKING(required_pfn) ) { /* break of a 2M extent, populate previous buf */ - if ( allocate_mfn_list(xc_handle, dom, + if ( allocate_mfn_list(xc_handle, dom, ctx, batch_buf_len, batch_buf, &required_pfn, superpages) !=3D 0 ) { @@ -404,7 +400,7 @@ static int allocate_physmem(int xc_handle, uint32_t d= om, alloc_page: if ( batch_buf ) { - if ( allocate_mfn_list(xc_handle, dom, + if ( allocate_mfn_list(xc_handle, dom, ctx, batch_buf_len, batch_buf, &required_pfn, superpages) !=3D 0 ) @@ -497,7 +493,7 @@ static ssize_t read_exact_timed(int fd, void* buf, si= ze_t size) ** This function inverts that operation, replacing the pfn values with ** the (now known) appropriate mfn values. */ -static int uncanonicalize_pagetable(int xc_handle, uint32_t dom,=20 +static int uncanonicalize_pagetable(int xc_handle, uint32_t dom, struct = restore_ctx *ctx, unsigned long type, void *page, int = superpages) { int i, pte_last; @@ -524,7 +520,7 @@ static int uncanonicalize_pagetable(int xc_handle, ui= nt32_t dom, if ( ctx->p2m[pfn] =3D=3D INVALID_P2M_ENTRY ) { unsigned long force_pfn =3D superpages ? FORCE_SP_MASK : pfn= ; - if (allocate_mfn_list(xc_handle, dom, + if (allocate_mfn_list(xc_handle, dom, ctx, 1, &pfn, &force_pfn, superpages) !=3D 0) return 0; } @@ -542,7 +538,7 @@ static int uncanonicalize_pagetable(int xc_handle, ui= nt32_t dom, =20 =20 /* Load the p2m frame list, plus potential extended info chunk */ -static xen_pfn_t *load_p2m_frame_list( +static xen_pfn_t *load_p2m_frame_list(struct restore_ctx *ctx, int io_fd, int *pae_extended_cr3, int *ext_vcpucontext) { xen_pfn_t *p2m_frame_list; @@ -798,7 +794,7 @@ static int dump_qemu(uint32_t dom, struct tailbuf_hvm= *buf) return 0; } =20 -static int buffer_tail_hvm(struct tailbuf_hvm *buf, int fd, +static int buffer_tail_hvm(struct restore_ctx *ctx, struct tailbuf_hvm *= buf, int fd, unsigned int max_vcpu_id, uint64_t vcpumap, int ext_vcpucontext) { @@ -859,7 +855,7 @@ static int buffer_tail_hvm(struct tailbuf_hvm *buf, i= nt fd, return -1; } =20 -static int buffer_tail_pv(struct tailbuf_pv *buf, int fd, +static int buffer_tail_pv(struct restore_ctx *ctx, struct tailbuf_pv *bu= f, int fd, unsigned int max_vcpu_id, uint64_t vcpumap, int ext_vcpucontext) { @@ -937,14 +933,14 @@ static int buffer_tail_pv(struct tailbuf_pv *buf, i= nt fd, return -1; } =20 -static int buffer_tail(tailbuf_t *buf, int fd, unsigned int max_vcpu_id, +static int buffer_tail(struct restore_ctx *ctx, tailbuf_t *buf, int fd, = unsigned int max_vcpu_id, uint64_t vcpumap, int ext_vcpucontext) { if ( buf->ishvm ) - return buffer_tail_hvm(&buf->u.hvm, fd, max_vcpu_id, vcpumap, + return buffer_tail_hvm(ctx, &buf->u.hvm, fd, max_vcpu_id, vcpuma= p, ext_vcpucontext); else - return buffer_tail_pv(&buf->u.pv, fd, max_vcpu_id, vcpumap, + return buffer_tail_pv(ctx, &buf->u.pv, fd, max_vcpu_id, vcpumap, ext_vcpucontext); } =20 @@ -1161,8 +1157,8 @@ static int pagebuf_get(pagebuf_t* buf, int fd, int = xch, uint32_t dom) return rc; } =20 -static int apply_batch(int xc_handle, uint32_t dom, xen_pfn_t* region_mf= n, - unsigned long* pfn_type, int pae_extended_cr3, +static int apply_batch(int xc_handle, uint32_t dom, struct restore_ctx *= ctx, + xen_pfn_t* region_mfn, unsigned long* pfn_type, i= nt pae_extended_cr3, unsigned int hvm, struct xc_mmu* mmu, pagebuf_t* pagebuf, int curbatch, int superpages) { @@ -1182,7 +1178,7 @@ static int apply_batch(int xc_handle, uint32_t dom,= xen_pfn_t* region_mfn, if (j > MAX_BATCH_SIZE) j =3D MAX_BATCH_SIZE; =20 - if (allocate_physmem(xc_handle, dom, &pagebuf->pfn_types[curbatch], + if (allocate_physmem(xc_handle, dom, ctx, &pagebuf->pfn_types[curbat= ch], j, hvm, region_mfn, superpages) !=3D 0) { ERROR("allocate_physmem() failed\n"); @@ -1243,7 +1239,7 @@ static int apply_batch(int xc_handle, uint32_t dom,= xen_pfn_t* region_mfn, pae_extended_cr3 || (pagetype !=3D XEN_DOMCTL_PFINFO_L1TAB)) { =20 - if (!uncanonicalize_pagetable(xc_handle, dom, + if (!uncanonicalize_pagetable(xc_handle, dom, ctx, pagetype, page, superpages= )) { /* ** Failing to uncanonicalize a page table can be ok @@ -1350,6 +1346,12 @@ int xc_domain_restore(int xc_handle, int io_fd, ui= nt32_t dom, tailbuf_t tailbuf, tmptail; void* vcpup; =20 + static struct restore_ctx _ctx =3D { + .live_p2m =3D NULL, + .p2m =3D NULL, + .no_superpage_mem =3D 0, + }; + static struct restore_ctx *ctx =3D &_ctx; struct domain_info_context *dinfo =3D &ctx->dinfo; =20 pagebuf_init(&pagebuf); @@ -1386,7 +1388,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uin= t32_t dom, if ( !hvm )=20 { /* Load the p2m frame list, plus potential extended info chunk *= / - p2m_frame_list =3D load_p2m_frame_list( + p2m_frame_list =3D load_p2m_frame_list(ctx, io_fd, &pae_extended_cr3, &ext_vcpucontext); if ( !p2m_frame_list ) goto out; @@ -1500,7 +1502,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uin= t32_t dom, while ( curbatch < j ) { int brc; =20 - brc =3D apply_batch(xc_handle, dom, region_mfn, pfn_type, + brc =3D apply_batch(xc_handle, dom, ctx, region_mfn, pfn_typ= e, pae_extended_cr3, hvm, mmu, &pagebuf, curb= atch, superpages); if ( brc < 0 ) goto out; @@ -1541,7 +1543,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uin= t32_t dom, if ( !completed ) { int flags =3D 0; =20 - if ( buffer_tail(&tailbuf, io_fd, max_vcpu_id, vcpumap, + if ( buffer_tail(ctx, &tailbuf, io_fd, max_vcpu_id, vcpumap, ext_vcpucontext) < 0 ) { ERROR ("error buffering image tail"); goto out; @@ -1561,7 +1563,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uin= t32_t dom, } memset(&tmptail, 0, sizeof(tmptail)); tmptail.ishvm =3D hvm; - if ( buffer_tail(&tmptail, io_fd, max_vcpu_id, vcpumap, + if ( buffer_tail(ctx, &tmptail, io_fd, max_vcpu_id, vcpumap, ext_vcpucontext) < 0 ) { ERROR ("error buffering image tail, finishing"); goto finish; @@ -1664,7 +1666,7 @@ int xc_domain_restore(int xc_handle, int io_fd, uin= t32_t dom, for ( k =3D 0; k < j; k++ ) { if ( !uncanonicalize_pagetable( - xc_handle, dom, XEN_DOMCTL_PFINFO_L1TAB, + xc_handle, dom, ctx, XEN_DOMCTL_PFINFO_L1TAB, region_base + k*PAGE_SIZE, superpages) ) { ERROR("failed uncanonicalize pt!"); --------------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--