From nobody Mon Feb 9 09:32:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1603992258; cv=none; d=zohomail.com; s=zohoarc; b=bjEqiomWcNAPmuZYNoGWKv0UEYPE3V5E81Xonrz9AoxyVc/jVo1DN0fhM4ZSNzT7XBDZqMAwfgY92aUZLvnSlL5Q/YupK1AJ4jxGWJ6NQ06UkImi67vGBLxAkZBMFZtUkaKg30S56fKk9uNut4S6Y1qmqCpJuYVfVG5nlELjOpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603992258; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bBxHDLx7AeMPpHXep28OEFmN0H0Z0pHfYy9VAoYWQzc=; b=J6EykJz93/H3+uRGuPhoc4NSTS1AwmP1YnvAscgYHUNlmY9Y1POorjEl2PttxGmnDuj063Ukk32X/vLZKd9lfQz8tcOXjWhlntDc5X6EJ744XsX4563B6Sufcv10hOgBJ3h3f1/bLQ+hBriDZbP4+cgcWThSUYKPW98zfZ7X+TI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1603992258670232.3526020343852; Thu, 29 Oct 2020 10:24:18 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.14496.35851 (Exim 4.92) (envelope-from ) id 1kYBea-0005rI-Rh; Thu, 29 Oct 2020 17:24:00 +0000 Received: by outflank-mailman (output) from mailman id 14496.35851; Thu, 29 Oct 2020 17:24:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBea-0005r6-OB; Thu, 29 Oct 2020 17:24:00 +0000 Received: by outflank-mailman (input) for mailman id 14496; Thu, 29 Oct 2020 17:23:59 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbw-0003MC-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:16 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8d6ec06d-e896-4655-b970-ab122dacae12; Thu, 29 Oct 2020 17:20:25 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fV (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kYBbw-0003MC-ND for xen-devel@lists.xenproject.org; Thu, 29 Oct 2020 17:21:16 +0000 Received: from mo4-p03-ob.smtp.rzone.de (unknown [85.215.255.104]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8d6ec06d-e896-4655-b970-ab122dacae12; Thu, 29 Oct 2020 17:20:25 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.3.0 DYNA|AUTH) with ESMTPSA id j0b1afw9THKH3fV (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Thu, 29 Oct 2020 18:20:17 +0100 (CET) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 8d6ec06d-e896-4655-b970-ab122dacae12 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1603992024; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=bBxHDLx7AeMPpHXep28OEFmN0H0Z0pHfYy9VAoYWQzc=; b=qDoMP6d0d7wEn447iURC/emTuLvga9PR96Ko4Iv7jidNwnAlMoBUAnRGmLKo4HZLGA GHOgirg4mmXFYlap6+tmFd5Ax0PCMpMPTMzUiK29J/IrzDDArLcwmsNHAELVYY7r1ZTE XeoSFGmaiu8nGMKG9l/us2OUAYNWKdnizZuFmnjh4vohK5OWUQ5Psk0IdJ/P++i2UZzL HIIx55HWepCb0R8+J2HVGu0gyxQYcOdu5Qf6HumxN1ZfjMbpg0FamnYRlSSnmskzTIvx gf+hZWMFtprVMiitlaZlIGLimIhY1iIum9npDeoa/wSMzhXEffG/CAI+MYNWt6VI+cRm syTQ== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuzBW/OdlBZQ4AHSS3G1Jjw==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v1 23/23] tools/guest: restore: write data directly into guest Date: Thu, 29 Oct 2020 18:20:03 +0100 Message-Id: <20201029172004.17219-24-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201029172004.17219-1-olaf@aepfle.de> References: <20201029172004.17219-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Read incoming migration stream directly into the guest memory. This avoids the memory allocation and copying, and the resulting performance penalty. Signed-off-by: Olaf Hering --- tools/libs/guest/xg_sr_common.h | 1 + tools/libs/guest/xg_sr_restore.c | 132 ++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 7ec8867b88..f76af23bcc 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -231,6 +231,7 @@ struct xc_sr_restore_arrays { xen_pfn_t mfns[MAX_BATCH_SIZE]; int map_errs[MAX_BATCH_SIZE]; void *guest_data[MAX_BATCH_SIZE]; + struct iovec iov[MAX_BATCH_SIZE]; =20 /* populate_pfns */ xen_pfn_t pp_mfns[MAX_BATCH_SIZE]; diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 060f3d1f4e..2f575d7dd9 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -392,6 +392,122 @@ err: return rc; } =20 +/* + * Handle PAGE_DATA record from the stream. + * 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 co= py + * the data into the guest. + */ +static int handle_incoming_page_data(struct xc_sr_context *ctx, + struct xc_sr_rhdr *rhdr) +{ + xc_interface *xch =3D ctx->xch; + struct xc_sr_restore_arrays *m =3D ctx->restore.m; + struct xc_sr_rec_page_data_header *pages =3D &m->pages; + uint64_t *pfn_nums =3D m->pages.pfn; + uint32_t i; + int rc, iov_idx; + + rc =3D handle_static_data_end_v2(ctx); + if ( rc ) + goto err; + + /* First read and verify the header */ + rc =3D read_exact(ctx->fd, pages, sizeof(*pages)); + if ( rc ) + { + PERROR("Could not read rec_pfn header"); + goto err; + } + + if ( verify_rec_page_hdr(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Then read and verify the incoming pfn numbers */ + rc =3D read_exact(ctx->fd, pfn_nums, sizeof(*pfn_nums) * pages->count); + if ( rc ) + { + PERROR("Could not read rec_pfn data"); + goto err; + } + + if ( verify_rec_page_pfns(ctx, rhdr->length, pages) =3D=3D false ) + { + rc =3D -1; + goto err; + } + + /* Finally read and verify the incoming pfn data */ + rc =3D map_guest_pages(ctx, pages); + if ( rc ) + goto err; + + /* Prepare read buffers, either guest or throw away memory */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + m->iov[iov_idx].iov_len =3D PAGE_SIZE; + if ( ctx->restore.verify ) + m->iov[iov_idx].iov_base =3D ctx->restore.verify_buf + i * PAG= E_SIZE; + else + m->iov[iov_idx].iov_base =3D m->guest_data[i]; + iov_idx++; + } + + if ( !iov_idx ) + goto done; + + rc =3D readv_exact(ctx->fd, m->iov, iov_idx); + if ( rc ) + { + PERROR("read of %d pages failed", iov_idx); + goto err; + } + + /* Post-processing of pfn data */ + for ( i =3D 0, iov_idx =3D 0; i < pages->count; i++ ) + { + if ( !m->guest_data[i] ) + continue; + + rc =3D ctx->restore.ops.localise_page(ctx, m->types[i], m->iov[iov= _idx].iov_base); + if ( rc ) + { + ERROR("Failed to localise pfn %#"PRIpfn" (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SHIFT); + goto err; + + } + + if ( ctx->restore.verify ) + { + if ( memcmp(m->guest_data[i], m->iov[iov_idx].iov_base, PAGE_S= IZE) ) + { + ERROR("verify pfn %#"PRIpfn" failed (type %#"PRIx32")", + m->pfns[i], m->types[i] >> XEN_DOMCTL_PFINFO_LTAB_SH= IFT); + } + } + + iov_idx++; + } + +done: + rc =3D 0; + +err: + if ( ctx->restore.guest_mapping ) + { + xenforeignmemory_unmap(xch->fmem, ctx->restore.guest_mapping, ctx-= >restore.nr_mapped_pages); + ctx->restore.guest_mapping =3D NULL; + } + return rc; +} + /* * Handle PAGE_DATA record from an existing buffer * Given a list of pfns, their types, and a block of page data from the @@ -773,11 +889,19 @@ static int process_incoming_record_header(struct xc_s= r_context *ctx, struct xc_s struct xc_sr_record rec; int rc; =20 - rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); - if ( rc ) - return rc; + switch ( rhdr->type ) + { + case REC_TYPE_PAGE_DATA: + rc =3D handle_incoming_page_data(ctx, rhdr); + break; + default: + rc =3D read_record_data(ctx, ctx->fd, rhdr, &rec); + if ( rc =3D=3D 0 ) + rc =3D process_buffered_record(ctx, &rec);; + break; + } =20 - return process_buffered_record(ctx, &rec); + return rc; } =20 =20