From patchwork Mon Mar 27 09:06:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Otto X-Patchwork-Id: 9645691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 81B9960328 for ; Mon, 27 Mar 2017 09:09:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 699A527A98 for ; Mon, 27 Mar 2017 09:09:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E50C27B2F; Mon, 27 Mar 2017 09:09:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBF302833B for ; Mon, 27 Mar 2017 09:09:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csQcu-0004nY-2v; Mon, 27 Mar 2017 09:07:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1csQcs-0004mj-Sg for xen-devel@lists.xenproject.org; Mon, 27 Mar 2017 09:07:47 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id D0/7F-27751-266D8D85; Mon, 27 Mar 2017 09:07:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsXSmNjwSTfx2o0 Ig+dTVSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyG90uYC3arV9xb/oytgfGhTBcjF4eQwBIm iXsnNjN2MXJysAj4SBzccJsNJMEi8J9J4sLuO6wgCTYBdYntizayg9giAkoS91ZNZgIpYhY4y Chx5vxhZpCEsICjxIqdTVCTVCXWfFwF1sAr4Czx+dANsLiEgJzEzXOdYPWcAi4Sxy4eYgOxhY Bqrh3uhaoplui8uoOli5EDyA6R6L1pBRHWkTj64i1USbzE/v2zmSBKTCQeTPGECItKdB9+xgh ymoTAfEaJOT+2MU9gFF7AyLCKUaM4tagstUjX2FgvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScx qVgvOT93EyMwQBmAYAfjzvWBhxglOZiURHk/nL4RIcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCN +AqUE6wKDU9tSItMwcYKzBpCQ4eJRFeDZA0b3FBYm5xZjpE6hSjopQ4ryBIQgAkkVGaB9cGi8 9LjLJSwryMQIcI8RSkFuVmlqDKv2IU52BUEua1B5nCk5lXAjf9FdBiJqDFh+eDLS5JREhJNTB aLGdpO/rZ85NjMZOpzeoCuR0uElcazsV+vLQ2JkiS9XLZg5rGlqqVYpNn2nVM29vv49JmdbDz cce1rDMHDmwxcYi5q/onbenmZssXCYxdx5QPOCyqK9Aqnz5Px+np5X7b+Z7POYWkeJXUOH4L5 8ftz738NFrZ0WRaxLW/e5i3ZYfXMev9e6bEUpyRaKjFXFScCAAVBaGvygIAAA== X-Env-Sender: jtotto@uwaterloo.ca X-Msg-Ref: server-11.tower-21.messagelabs.com!1490605664!64265440!1 X-Originating-IP: [129.97.128.242] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35875 invoked from network); 27 Mar 2017 09:07:45 -0000 Received: from mailchk-m06.uwaterloo.ca (HELO mailchk-m06.uwaterloo.ca) (129.97.128.242) by server-11.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Mar 2017 09:07:45 -0000 Received: from eagle.uwaterloo.ca (cs-auth-dc-129-97-60-142.dynamic.uwaterloo.ca [129.97.60.142]) (authenticated bits=0) by mailchk-m06.uwaterloo.ca (8.14.4/8.14.4) with ESMTP id v2R97DTL023326 (version=TLSv1/SSLv3 cipher=AES128-SHA256 bits=128 verify=NO); Mon, 27 Mar 2017 05:07:38 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 mailchk-m06.uwaterloo.ca v2R97DTL023326 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uwaterloo.ca; s=default; t=1490605661; bh=89nKx/pzxGxArzdbQXtkdGAjbmPg9RFJBmtiNywaG7M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yHCFvfeT1foBBLvm3KIQ7UH19pwu/iIrYUteNB4Sz0gcz9UeCQmmyjivQbZs0SqHf /woE/XqYRx5+f/7BBIu0VstwXEEi2MBxf9QPQndNy+idWzrRQRo/XlgAOF+Bh5qxE/ W+yqzjjp5vyF6YWrOVXcLGeTWxDmzthZMNP06HaQ= From: Joshua Otto To: xen-devel@lists.xenproject.org Date: Mon, 27 Mar 2017 05:06:17 -0400 Message-Id: <1490605592-12189-6-git-send-email-jtotto@uwaterloo.ca> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490605592-12189-1-git-send-email-jtotto@uwaterloo.ca> References: <1490605592-12189-1-git-send-email-jtotto@uwaterloo.ca> X-UUID: 5eb66288-2ce1-4143-b434-9d618d9793fd X-Miltered: at mailchk-m06 with ID 58D8D641.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Virus-Scanned: clamav-milter 0.99.2 at mailchk-m06 X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mailchk-m06.uwaterloo.ca [129.97.128.141]); Mon, 27 Mar 2017 05:07:41 -0400 (EDT) Cc: wei.liu2@citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, czylin@uwaterloo.ca, Joshua Otto , imhy.yang@gmail.com, hjarmstr@uwaterloo.ca Subject: [Xen-devel] [PATCH RFC 05/20] libxc/xc_sr: factor out filter_pages() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When processing a PAGE_DATA record, the restore side needs to set the types of incoming pages using the appropriate restore op and filter the list of pfns in the record to the subset that are 'backed' - ie. accompanied by real backing data in the stream that needs to be filled in. Both of these steps are also required when processing postcopy records, so factor it out into a common helper. No functional change. Signed-off-by: Joshua Otto --- tools/libxc/xc_sr_restore.c | 100 +++++++++++++++++++++++++++++++++----------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/tools/libxc/xc_sr_restore.c b/tools/libxc/xc_sr_restore.c index 481a904..8574ee8 100644 --- a/tools/libxc/xc_sr_restore.c +++ b/tools/libxc/xc_sr_restore.c @@ -194,6 +194,68 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned count, return rc; } +static void set_page_types(struct xc_sr_context *ctx, unsigned count, + xen_pfn_t *pfns, uint32_t *types) +{ + unsigned i; + + for ( i = 0; i < count; ++i ) + ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); +} + +/* + * Given count pfns and their types, allocate and fill in buffer bpfns with only + * those pfns that are 'backed' by real page data that needs to be migrated. + * The caller must later free() *bpfns. + * + * Returns 0 on success and non-0 on failure. *bpfns can be free()ed even after + * failure. + */ +static int filter_pages(struct xc_sr_context *ctx, + unsigned count, + xen_pfn_t *pfns, + uint32_t *types, + /* OUT */ unsigned *nr_pages, + /* OUT */ xen_pfn_t **bpfns) +{ + xc_interface *xch = ctx->xch; + unsigned i; + + *nr_pages = 0; + *bpfns = malloc(count * sizeof(*bpfns)); + if ( !(*bpfns) ) + { + ERROR("Failed to allocate %zu bytes to process page data", + count * (sizeof(*bpfns))); + return -1; + } + + for ( i = 0; i < count; ++i ) + { + switch ( types[i] ) + { + case XEN_DOMCTL_PFINFO_NOTAB: + + case XEN_DOMCTL_PFINFO_L1TAB: + case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L2TAB: + case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L3TAB: + case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + case XEN_DOMCTL_PFINFO_L4TAB: + case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: + + (*bpfns)[(*nr_pages)++] = pfns[i]; + break; + } + } + + return 0; +} + /* * Given a list of pfns, their types, and a block of page data from the * stream, populate and record their types, map the relevant subset and copy @@ -203,7 +265,7 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, xen_pfn_t *pfns, uint32_t *types, void *page_data) { xc_interface *xch = ctx->xch; - xen_pfn_t *mfns = malloc(count * sizeof(*mfns)); + xen_pfn_t *mfns = NULL; int *map_errs = malloc(count * sizeof(*map_errs)); int rc; void *mapping = NULL, *guest_page = NULL; @@ -211,11 +273,11 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, j, /* j indexes the subset of pfns we decide to map. */ nr_pages = 0; - if ( !mfns || !map_errs ) + if ( !map_errs ) { rc = -1; ERROR("Failed to allocate %zu bytes to process page data", - count * (sizeof(*mfns) + sizeof(*map_errs))); + count * sizeof(*map_errs)); goto err; } @@ -226,31 +288,19 @@ static int process_page_data(struct xc_sr_context *ctx, unsigned count, goto err; } - for ( i = 0; i < count; ++i ) - { - ctx->restore.ops.set_page_type(ctx, pfns[i], types[i]); - - switch ( types[i] ) - { - case XEN_DOMCTL_PFINFO_NOTAB: - - case XEN_DOMCTL_PFINFO_L1TAB: - case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L2TAB: - case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB: + set_page_types(ctx, count, pfns, types); - case XEN_DOMCTL_PFINFO_L3TAB: - case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - case XEN_DOMCTL_PFINFO_L4TAB: - case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB: - - mfns[nr_pages++] = ctx->restore.ops.pfn_to_gfn(ctx, pfns[i]); - break; - } + rc = filter_pages(ctx, count, pfns, types, &nr_pages, &mfns); + if ( rc ) + { + ERROR("Failed to filter mfns for batch of %u pages", count); + goto err; } + /* Map physically-backed pfns ('bpfns') to their gmfns. */ + for ( i = 0; i < nr_pages; ++i ) + mfns[i] = ctx->restore.ops.pfn_to_gfn(ctx, mfns[i]); + /* Nothing to do? */ if ( nr_pages == 0 ) goto done;