From patchwork Thu Jan 7 12:36:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 7976721 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0A2679F3E6 for ; Thu, 7 Jan 2016 12:40:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08FDC2015E for ; Thu, 7 Jan 2016 12:40:12 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 193362014A for ; Thu, 7 Jan 2016 12:40:11 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aH9oR-0004c6-Lg; Thu, 07 Jan 2016 12:37:07 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aH9oP-0004bn-Ds for xen-devel@lists.xen.org; Thu, 07 Jan 2016 12:37:05 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 4F/86-13905-0FB5E865; Thu, 07 Jan 2016 12:37:04 +0000 X-Env-Sender: jgross@suse.com X-Msg-Ref: server-15.tower-206.messagelabs.com!1452170219!14186703!1 X-Originating-IP: [195.135.220.15] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34258 invoked from network); 7 Jan 2016 12:37:00 -0000 Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by server-15.tower-206.messagelabs.com with DHE-RSA-CAMELLIA256-SHA encrypted SMTP; 7 Jan 2016 12:37:00 -0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 57CE0ABE5; Thu, 7 Jan 2016 12:36:58 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xen.org, Ian.Campbell@citrix.com, ian.jackson@eu.citrix.com, stefano.stabellini@eu.citrix.com, wei.liu2@citrix.com, andrew.cooper3@citrix.com Date: Thu, 7 Jan 2016 13:36:51 +0100 Message-Id: <1452170214-17821-2-git-send-email-jgross@suse.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1452170214-17821-1-git-send-email-jgross@suse.com> References: <1452170214-17821-1-git-send-email-jgross@suse.com> Cc: Juergen Gross Subject: [Xen-devel] [PATCH v4 1/4] libxc: split mapping p2m leaves into a separate function X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to prepare using the virtual mapped linear p2m list for migration split mapping of the p2m leaf pages into a separate function. Signed-off-by: Juergen Gross Reviewed-by: Andrew Cooper Acked-by: Wei Liu --- tools/libxc/xc_sr_save_x86_pv.c | 77 ++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 32 deletions(-) diff --git a/tools/libxc/xc_sr_save_x86_pv.c b/tools/libxc/xc_sr_save_x86_pv.c index c8d6f0b..d7acd37 100644 --- a/tools/libxc/xc_sr_save_x86_pv.c +++ b/tools/libxc/xc_sr_save_x86_pv.c @@ -68,6 +68,50 @@ static int copy_mfns_from_guest(const struct xc_sr_context *ctx, } /* + * Map the p2m leave pages and build an array of their pfns. + */ +static int map_p2m_leaves(struct xc_sr_context *ctx, xen_pfn_t *mfns, + size_t n_mfns) +{ + xc_interface *xch = ctx->xch; + unsigned x; + + ctx->x86_pv.p2m = xc_map_foreign_pages(xch, ctx->domid, PROT_READ, + mfns, n_mfns); + if ( !ctx->x86_pv.p2m ) + { + PERROR("Failed to map p2m frames"); + return -1; + } + + ctx->save.p2m_size = ctx->x86_pv.max_pfn + 1; + ctx->x86_pv.p2m_frames = n_mfns; + ctx->x86_pv.p2m_pfns = malloc(n_mfns * sizeof(*mfns)); + if ( !ctx->x86_pv.p2m_pfns ) + { + ERROR("Cannot allocate %zu bytes for p2m pfns list", + n_mfns * sizeof(*mfns)); + return -1; + } + + /* Convert leaf frames from mfns to pfns. */ + for ( x = 0; x < n_mfns; ++x ) + { + if ( !mfn_in_pseudophysmap(ctx, mfns[x]) ) + { + ERROR("Bad mfn in p2m_frame_list[%u]", x); + dump_bad_pseudophysmap_entry(ctx, mfns[x]); + errno = ERANGE; + return -1; + } + + ctx->x86_pv.p2m_pfns[x] = mfn_to_pfn(ctx, mfns[x]); + } + + return 0; +} + +/* * Walk the guests frame list list and frame list to identify and map the * frames making up the guests p2m table. Construct a list of pfns making up * the table. @@ -173,7 +217,6 @@ static int map_p2m(struct xc_sr_context *ctx) ctx->x86_pv.p2m_frames = (ctx->x86_pv.max_pfn + fpp) / fpp; DPRINTF("max_pfn %#lx, p2m_frames %d", ctx->x86_pv.max_pfn, ctx->x86_pv.p2m_frames); - ctx->save.p2m_size = ctx->x86_pv.max_pfn + 1; fl_entries = (ctx->x86_pv.max_pfn / fpp) + 1; /* Map the guest mid p2m frames. */ @@ -211,38 +254,8 @@ static int map_p2m(struct xc_sr_context *ctx) } /* Map the p2m leaves themselves. */ - ctx->x86_pv.p2m = xc_map_foreign_pages(xch, ctx->domid, PROT_READ, - local_fl, fl_entries); - if ( !ctx->x86_pv.p2m ) - { - PERROR("Failed to map p2m frames"); - goto err; - } + rc = map_p2m_leaves(ctx, local_fl, fl_entries); - ctx->x86_pv.p2m_frames = fl_entries; - ctx->x86_pv.p2m_pfns = malloc(local_fl_size); - if ( !ctx->x86_pv.p2m_pfns ) - { - ERROR("Cannot allocate %zu bytes for p2m pfns list", - local_fl_size); - goto err; - } - - /* Convert leaf frames from mfns to pfns. */ - for ( x = 0; x < fl_entries; ++x ) - { - if ( !mfn_in_pseudophysmap(ctx, local_fl[x]) ) - { - ERROR("Bad mfn in p2m_frame_list[%u]", x); - dump_bad_pseudophysmap_entry(ctx, local_fl[x]); - errno = ERANGE; - goto err; - } - - ctx->x86_pv.p2m_pfns[x] = mfn_to_pfn(ctx, local_fl[x]); - } - - rc = 0; err: free(local_fl);