From nobody Sun Apr 28 21:40:20 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1576779738; cv=none; d=zohomail.com; s=zohoarc; b=lNrrtVW0affDA2Jfea3tCQl/Wyj7y0P/VG2yjjd9UExzHYVKAB+2cblRgCTKrZWe5AECeY0EgfxSIR8ay6JLCyN0Bpzvut6qc/nc4zL2D1pxUWms4tgRxJjBUfdt2gfcSjlZ6f9LZ0CPI4rXL+BjarXOtI6aExauIkVJ+fp69m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576779738; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=dUNZw7mBIPqSya2wsOgvXkTSiWfEYFIs2Fc1kYzpzZ0=; b=F9x59/LomUaHcQdKIXRxQYXozVGF1RTFnVQfv6gArpp0/JtEYeDpNzeyrLQ/K16d1EzI/AuaXbL9G74AaacTgFfwFSEXHc7okPWiFpSLWuftWjfzvtG3csWXPUzpBMbyoO9dYvlPXF1JzTnlySipfPmd5sfKiyicVegffveRDUg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576779738128986.4863460626282; Thu, 19 Dec 2019 10:22:18 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ii0QU-0002Z0-GN; Thu, 19 Dec 2019 18:21:30 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ii0QT-0002Yv-72 for xen-devel@lists.xenproject.org; Thu, 19 Dec 2019 18:21:29 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5a0f626c-228c-11ea-b6f1-bc764e2007e4; Thu, 19 Dec 2019 18:21:19 +0000 (UTC) X-Inumbo-ID: 5a0f626c-228c-11ea-b6f1-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576779679; h=from:to:cc:subject:date:message-id:mime-version; bh=BzgVL9yUm5d02322hri4Dur9TL0XprDEoRkGuiJMILs=; b=ISPJsHLXcvC+B3zwjoDveZRwHwpvBUZstE7/k1PDhCUtH7TeGIGmVTEf CYbUwzD2l8jz8LwRSGMv7Cd4FxVQB+iZEf6wcM1uAXUUpUJ+UEpJnW3qP 9OLP8K6UZjRSL9XDVU5VsgsMPqrr4I+HvugSLEbi/w8rdGy7Psq/R0Q6r M=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: etEHDAzv5P3tUAZlkFHKAQy+2x53a4vtYc0lMKzfWsPZFtwypKYfd1nUpWcf/1jnVlsrISYhl8 +EWjN2Rmk8y+qGAmdF+RE52aaO2849gFuWzLzh8oL/cUgRVKvPTMW7ezWpr+VZW+6z6/jgc2+p QujJerlMqN8fO9zg6YLU0L+3QxZ3PdKXh/Kvpn3enZM3MwmxsrNxxgPj0nglird/HwKBygXmUP VdU6Ld/DKN0ICXTyaMzLf8xfVHGsre+Ld4/MmW4Qkj6avLWiwml2w8BjZwdwU4E91Y6pkM/+GC xj0= X-SBRS: 2.7 X-MesageID: 10317890 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,332,1571716800"; d="scan'208";a="10317890" From: Andrew Cooper To: Xen-devel Date: Thu, 19 Dec 2019 18:21:15 +0000 Message-ID: <20191219182115.1432-1-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] tools/libxc: Drop unused xc_compression_*() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , Wei Liu , Ian Jackson Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) There have been no users of the xc_compression_*() interface since Migration v2 replaced legacy migration (2016, c/s b15bc4345). It would need adjusting to fit into migration v2, and can be pulled out of = git history if someone wants to resurrect it in the future. Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu --- tools/libxc/Makefile | 2 +- tools/libxc/include/xenctrl.h | 60 ----- tools/libxc/xc_compression.c | 545 --------------------------------------= ---- 3 files changed, 1 insertion(+), 606 deletions(-) delete mode 100644 tools/libxc/xc_compression.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index cbc30001f6..6d0af563c0 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -63,7 +63,7 @@ GUEST_SRCS-$(CONFIG_X86) +=3D xc_sr_save_x86_pv.c GUEST_SRCS-$(CONFIG_X86) +=3D xc_sr_save_x86_hvm.c GUEST_SRCS-y +=3D xc_sr_restore.c GUEST_SRCS-y +=3D xc_sr_save.c -GUEST_SRCS-y +=3D xc_offline_page.c xc_compression.c +GUEST_SRCS-y +=3D xc_offline_page.c else GUEST_SRCS-y +=3D xc_nomigrate.c endif diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index f4431687b3..983f5ac6b0 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2315,66 +2315,6 @@ void xc_elf_set_logfile(xc_interface *xch, struct el= f_binary *elf, int verbose); /* Useful for callers who also use libelf. */ =20 -/** - * Checkpoint Compression - */ -typedef struct compression_ctx comp_ctx; -comp_ctx *xc_compression_create_context(xc_interface *xch, - unsigned long p2m_size); -void xc_compression_free_context(xc_interface *xch, comp_ctx *ctx); - -/** - * Add a page to compression page buffer, to be compressed later. - * - * returns 0 if the page was successfully added to the page buffer - * - * returns -1 if there is no space in buffer. In this case, the - * application should call xc_compression_compress_pages to compress - * the buffer (or atleast part of it), thereby freeing some space in - * the page buffer. - * - * returns -2 if the pfn is out of bounds, where the bound is p2m_size - * parameter passed during xc_compression_create_context. - */ -int xc_compression_add_page(xc_interface *xch, comp_ctx *ctx, char *page, - unsigned long pfn, int israw); - -/** - * Delta compress pages in the compression buffer and inserts the - * compressed data into the supplied compression buffer compbuf, whose - * size is compbuf_size. - * After compression, the pages are copied to the internal LRU cache. - * - * This function compresses as many pages as possible into the - * supplied compression buffer. It maintains an internal iterator to - * keep track of pages in the input buffer that are yet to be compressed. - * - * returns -1 if the compression buffer has run out of space. =20 - * returns 1 on success. - * returns 0 if no more pages are left to be compressed. - * When the return value is non-zero, compbuf_len indicates the actual - * amount of data present in compbuf (<=3Dcompbuf_size). - */ -int xc_compression_compress_pages(xc_interface *xch, comp_ctx *ctx, - char *compbuf, unsigned long compbuf_size, - unsigned long *compbuf_len); - -/** - * Resets the internal page buffer that holds dirty pages before compressi= on. - * Also resets the iterators. - */ -void xc_compression_reset_pagebuf(xc_interface *xch, comp_ctx *ctx); - -/** - * Caller must supply the compression buffer (compbuf), - * its size (compbuf_size) and a reference to index variable (compbuf_pos) - * that is used internally. Each call pulls out one page from the compress= ed - * chunk and copies it to dest. - */ -int xc_compression_uncompress_page(xc_interface *xch, char *compbuf, - unsigned long compbuf_size, - unsigned long *compbuf_pos, char *dest); - /* * Execute an image previously loaded with xc_kexec_load(). * diff --git a/tools/libxc/xc_compression.c b/tools/libxc/xc_compression.c deleted file mode 100644 index 89c1114ebb..0000000000 --- a/tools/libxc/xc_compression.c +++ /dev/null @@ -1,545 +0,0 @@ -/*************************************************************************= ***** - * xc_compression.c - * - * Checkpoint Compression using Page Delta Algorithm. - * - A LRU cache of recently dirtied guest pages is maintained. - * - For each dirty guest page in the checkpoint, if a previous version of= the - * page exists in the cache, XOR both pages and send the non-zero sections - * to the receiver. The cache is then updated with the newer copy of guest= page. - * - The receiver will XOR the non-zero sections against its copy of the g= uest - * page, thereby bringing the guest page up-to-date with the sender side. - * - * Copyright (c) 2011 Shriram Rajagopalan (rshriram@cs.ubc.ca). - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; If not, see . - * - */ - -#include -#include -#include -#include -#include -#include "xc_private.h" -#include "xenctrl.h" -#include "xg_save_restore.h" -#include "xg_private.h" -#include "xc_dom.h" - -/* Page Cache for Delta Compression*/ -#define DELTA_CACHE_SIZE (XC_PAGE_SIZE * 8192) - -/* Internal page buffer to hold dirty pages of a checkpoint, - * to be compressed after the domain is resumed for execution. - */ -#define PAGE_BUFFER_SIZE (XC_PAGE_SIZE * 8192) - -struct cache_page -{ - char *page; - xen_pfn_t pfn; - struct cache_page *next; - struct cache_page *prev; -}; - -struct compression_ctx -{ - /* compression buffer - holds compressed data */ - char *compbuf; - unsigned long compbuf_size; - unsigned long compbuf_pos; - - /* Page buffer to hold pages to be compressed */ - char *inputbuf; - /* pfns of pages to be compressed */ - xen_pfn_t *sendbuf_pfns; - unsigned int pfns_len; - unsigned int pfns_index; - - /* Compression Cache (LRU) */ - char *cache_base; - struct cache_page **pfn2cache; - struct cache_page *cache; - struct cache_page *page_list_head; - struct cache_page *page_list_tail; - unsigned long dom_pfnlist_size; -}; - -#define RUNFLAG 0 -#define SKIPFLAG ((char)128) -#define FLAGMASK SKIPFLAG -#define LENMASK ((char)127) - -/* - * see xg_save_restore.h for details on the compressed stream format. - * delta size =3D 4 bytes. - * run header =3D 1 byte (1 bit for runtype, 7bits for run length). - * i.e maximum size of a run =3D 127 * 4 =3D 508 bytes. - * Worst case compression: Entire page has changed. - * In the worst case, the size of the compressed page is - * 8 runs of 508 bytes + 1 run of 32 bytes + 9 run headers=20 - * =3D 4105 bytes. - * We could detect this worst case and send the entire page with a - * FULL_PAGE marker, reducing the total size to 4097 bytes. The cost - * of this size reduction is an additional memcpy, on top of two previous - * memcpy (to the compressed stream and the cache page in the for loop). - * - * We might as well sacrifice an extra 8 bytes instead of a memcpy. - */ -#define WORST_COMP_PAGE_SIZE (XC_PAGE_SIZE + 9) - -/* - * A zero length skip indicates full page. - */ -#define EMPTY_PAGE 0 -#define FULL_PAGE SKIPFLAG -#define FULL_PAGE_SIZE (XC_PAGE_SIZE + 1) -#define MAX_DELTAS (XC_PAGE_SIZE/sizeof(uint32_t)) - -/* - * Add a pagetable page or a new page (uncached) - * if srcpage is a pagetable page, cache_page is null. - * if srcpage is a page that was not previously in the cache, - * cache_page points to a free page slot in the cache where - * this new page can be copied to. - */ -static int add_full_page(comp_ctx *ctx, char *srcpage, char *cache_page) -{ - char *dest =3D (ctx->compbuf + ctx->compbuf_pos); - - if ( (ctx->compbuf_pos + FULL_PAGE_SIZE) > ctx->compbuf_size) - return -1; - - if (cache_page) - memcpy(cache_page, srcpage, XC_PAGE_SIZE); - dest[0] =3D FULL_PAGE; - memcpy(&dest[1], srcpage, XC_PAGE_SIZE); - ctx->compbuf_pos +=3D FULL_PAGE_SIZE; - - return FULL_PAGE_SIZE; -} - -static int compress_page(comp_ctx *ctx, char *srcpage, char *cache_page) -{ - char *dest =3D (ctx->compbuf + ctx->compbuf_pos); - uint32_t *new, *old; - - int off, runptr =3D 0; - int wascopying =3D 0, copying =3D 0, bytes_skipped =3D 0; - int complen =3D 0, pageoff =3D 0, runbytes =3D 0; - - char runlen =3D 0; - - if ( (ctx->compbuf_pos + WORST_COMP_PAGE_SIZE) > ctx->compbuf_size) - return -1; - - /* - * There are no alignment issues here since srcpage is - * domU's page passed from xc_domain_save and cache_page is - * a ptr to cache page (cache is page aligned). - */ - new =3D (uint32_t*)srcpage; - old =3D (uint32_t*)cache_page; - - for (off =3D 0; off <=3D MAX_DELTAS; off++) - { - /* - * At (off =3D=3D MAX_DELTAS), we are processing the last run - * in the page. Since there is no XORing, make wascopying !=3D cop= ying - * to satisfy the if-block below. - */ - copying =3D ((off < MAX_DELTAS) ? (old[off] !=3D new[off]) : !wasc= opying); - - if (runlen) - { - /* switching between run types or current run is full */ - if ( (wascopying !=3D copying) || (runlen =3D=3D LENMASK) ) - { - runbytes =3D runlen * sizeof(uint32_t); - runlen |=3D (wascopying ? RUNFLAG : SKIPFLAG); - dest[complen++] =3D runlen; - - if (wascopying) /* RUNFLAG */ - { - pageoff =3D runptr * sizeof(uint32_t); - memcpy(dest + complen, srcpage + pageoff, runbytes); - memcpy(cache_page + pageoff, srcpage + pageoff, runbyt= es); - complen +=3D runbytes; - } - else /* SKIPFLAG */ - { - bytes_skipped +=3D runbytes; - } - - runlen =3D 0; - runptr =3D off; - } - } - runlen++; - wascopying =3D copying; - } - - /* - * Check for empty page. - */ - if (bytes_skipped =3D=3D XC_PAGE_SIZE) - { - complen =3D 1; - dest[0] =3D EMPTY_PAGE; - } - ctx->compbuf_pos +=3D complen; - - return complen; -} - -static -char *get_cache_page(comp_ctx *ctx, xen_pfn_t pfn, - int *israw) -{ - struct cache_page *item =3D NULL; - - item =3D ctx->pfn2cache[pfn]; - - if (!item) - { - *israw =3D 1; - - /* If the list is full, evict a page from the tail end. */ - item =3D ctx->page_list_tail; - if (item->pfn !=3D INVALID_PFN) - ctx->pfn2cache[item->pfn] =3D NULL; - - item->pfn =3D pfn; - ctx->pfn2cache[pfn] =3D item; - } - =20 - /* if requested item is in cache move to head of list */ - if (item !=3D ctx->page_list_head) - { - if (item =3D=3D ctx->page_list_tail) - { - /* item at tail of list. */ - ctx->page_list_tail =3D item->prev; - (ctx->page_list_tail)->next =3D NULL; - } - else - { - /* item in middle of list */ - item->prev->next =3D item->next; - item->next->prev =3D item->prev; - } - - item->prev =3D NULL; - item->next =3D ctx->page_list_head; - (ctx->page_list_head)->prev =3D item; - ctx->page_list_head =3D item; - } - - return (ctx->page_list_head)->page; -} - -/* Remove pagetable pages from cache and move to tail, as free pages */ -static -void invalidate_cache_page(comp_ctx *ctx, xen_pfn_t pfn) -{ - struct cache_page *item =3D NULL; - - item =3D ctx->pfn2cache[pfn]; - if (item) - { - if (item !=3D ctx->page_list_tail) - { - /* item at head of list */ - if (item =3D=3D ctx->page_list_head) - { - ctx->page_list_head =3D (ctx->page_list_head)->next; - (ctx->page_list_head)->prev =3D NULL; - } - else /* item in middle of list */ - { =20 - item->prev->next =3D item->next; - item->next->prev =3D item->prev; - } - - item->next =3D NULL; - item->prev =3D ctx->page_list_tail; - (ctx->page_list_tail)->next =3D item; - ctx->page_list_tail =3D item; - } - ctx->pfn2cache[pfn] =3D NULL; - (ctx->page_list_tail)->pfn =3D INVALID_PFN; - } -} - -int xc_compression_add_page(xc_interface *xch, comp_ctx *ctx, - char *page, xen_pfn_t pfn, int israw) -{ - if (pfn > ctx->dom_pfnlist_size) - { - ERROR("Invalid pfn passed into " - "xc_compression_add_page %" PRIpfn "\n", pfn); - return -2; - } - - /* pagetable page */ - if (israw) - invalidate_cache_page(ctx, pfn); - ctx->sendbuf_pfns[ctx->pfns_len] =3D israw ? INVALID_PFN : pfn; - memcpy(ctx->inputbuf + ctx->pfns_len * XC_PAGE_SIZE, page, XC_PAGE_SIZ= E); - ctx->pfns_len++; - - /* check if we have run out of space. If so, - * we need to synchronously compress the pages and flush them out - */ - if (ctx->pfns_len =3D=3D NRPAGES(PAGE_BUFFER_SIZE)) - return -1; - return 0; -} - -int xc_compression_compress_pages(xc_interface *xch, comp_ctx *ctx, - char *compbuf, unsigned long compbuf_siz= e, - unsigned long *compbuf_len) -{ - char *cache_copy =3D NULL, *current_page =3D NULL; - int israw, rc =3D 1; - - if (!ctx->pfns_len || (ctx->pfns_index =3D=3D ctx->pfns_len)) { - ctx->pfns_len =3D ctx->pfns_index =3D 0; - return 0; - } - - ctx->compbuf_pos =3D 0; - ctx->compbuf =3D compbuf; - ctx->compbuf_size =3D compbuf_size; - - for (; ctx->pfns_index < ctx->pfns_len; ctx->pfns_index++) - { - israw =3D 0; - cache_copy =3D NULL; - current_page =3D ctx->inputbuf + ctx->pfns_index * XC_PAGE_SIZE; - - if (ctx->sendbuf_pfns[ctx->pfns_index] =3D=3D INVALID_PFN) - israw =3D 1; - else - cache_copy =3D get_cache_page(ctx, - ctx->sendbuf_pfns[ctx->pfns_index], - &israw); - - if (israw) - rc =3D (add_full_page(ctx, current_page, cache_copy) >=3D 0); - else - rc =3D (compress_page(ctx, current_page, cache_copy) >=3D 0); - - if ( !rc ) - { - /* Out of space in outbuf! flush and come back */ - rc =3D -1; - break; - } - } - if (compbuf_len) - *compbuf_len =3D ctx->compbuf_pos; - - return rc; -} - -inline -void xc_compression_reset_pagebuf(xc_interface *xch, comp_ctx *ctx) -{ - ctx->pfns_index =3D ctx->pfns_len =3D 0; -} - -int xc_compression_uncompress_page(xc_interface *xch, char *compbuf, - unsigned long compbuf_size, - unsigned long *compbuf_pos, char *destp= age) -{ - unsigned long pos; - unsigned int len =3D 0, pagepos =3D 0; - char flag; - - pos =3D *compbuf_pos; - if (pos >=3D compbuf_size) - { - ERROR("Out of bounds exception in compression buffer (a):" - "read ptr:%lu, bufsize =3D %lu\n", - *compbuf_pos, compbuf_size); - return -1; - } - - switch (compbuf[pos]) - { - case EMPTY_PAGE: - pos++; - break; - - case FULL_PAGE: - { - /* Check if the input buffer has 4KB of data */ - if ((pos + FULL_PAGE_SIZE) > compbuf_size) - { - ERROR("Out of bounds exception in compression buffer (b):" - "read ptr =3D %lu, bufsize =3D %lu\n", - *compbuf_pos, compbuf_size); - return -1; - } - memcpy(destpage, &compbuf[pos + 1], XC_PAGE_SIZE); - pos +=3D FULL_PAGE_SIZE; - } - break; - - default: /* Normal page with one or more runs */ - { - do - { - flag =3D compbuf[pos] & FLAGMASK; - len =3D (compbuf[pos] & LENMASK) * sizeof(uint32_t); - /* Sanity Check: Zero-length runs are allowed only for - * FULL_PAGE and EMPTY_PAGE. - */ - if (!len) - { - ERROR("Zero length run encountered for normal page: " - "buffer (d):read ptr =3D %lu, flag =3D %u, " - "bufsize =3D %lu, pagepos =3D %u\n", - pos, (unsigned int)flag, compbuf_size, pagepos); - return -1; - } - - pos++; - if (flag =3D=3D RUNFLAG) - { - /* Check if the input buffer has len bytes of data - * and whether it would fit in the destination page. - */ - if (((pos + len) > compbuf_size) - || ((pagepos + len) > XC_PAGE_SIZE)) - { - ERROR("Out of bounds exception in compression " - "buffer (c):read ptr =3D %lu, runlen =3D %u,= " - "bufsize =3D %lu, pagepos =3D %u\n", - pos, len, compbuf_size, pagepos); - return -1; - } - memcpy(&destpage[pagepos], &compbuf[pos], len); - pos +=3D len; - } - pagepos +=3D len; - } while ((pagepos < XC_PAGE_SIZE) && (pos < compbuf_size)); - - /* Make sure we have copied/skipped 4KB worth of data */ - if (pagepos !=3D XC_PAGE_SIZE) - { - ERROR("Invalid data in compression buffer:" - "read ptr =3D %lu, bufsize =3D %lu, pagepos =3D %u\n= ", - pos, compbuf_size, pagepos); - return -1; - } - } - } - *compbuf_pos =3D pos; - return 0; -} - -void xc_compression_free_context(xc_interface *xch, comp_ctx *ctx) -{ - if (!ctx) return; - - free(ctx->inputbuf); - free(ctx->sendbuf_pfns); - free(ctx->cache_base); - free(ctx->pfn2cache); - free(ctx->cache); - free(ctx); -} - -comp_ctx *xc_compression_create_context(xc_interface *xch, - unsigned long p2m_size) -{ - unsigned long i; - comp_ctx *ctx =3D NULL; - unsigned long num_cache_pages =3D DELTA_CACHE_SIZE/XC_PAGE_SIZE; - - ctx =3D (comp_ctx *)malloc(sizeof(comp_ctx)); - if (!ctx) - { - ERROR("Failed to allocate compression_ctx\n"); - goto error; - } - memset(ctx, 0, sizeof(comp_ctx)); - - ctx->inputbuf =3D xc_memalign(xch, XC_PAGE_SIZE, PAGE_BUFFER_SIZE); - if (!ctx->inputbuf) - { - ERROR("Failed to allocate page buffer\n"); - goto error; - } - - ctx->cache_base =3D xc_memalign(xch, XC_PAGE_SIZE, DELTA_CACHE_SIZE); - if (!ctx->cache_base) - { - ERROR("Failed to allocate delta cache\n"); - goto error; - } - - ctx->sendbuf_pfns =3D malloc(NRPAGES(PAGE_BUFFER_SIZE) * - sizeof(xen_pfn_t)); - if (!ctx->sendbuf_pfns) - { - ERROR("Could not alloc sendbuf_pfns\n"); - goto error; - } - memset(ctx->sendbuf_pfns, -1, - NRPAGES(PAGE_BUFFER_SIZE) * sizeof(xen_pfn_t)); - - ctx->pfn2cache =3D calloc(p2m_size, sizeof(struct cache_page *)); - if (!ctx->pfn2cache) - { - ERROR("Could not alloc pfn2cache map\n"); - goto error; - } - - ctx->cache =3D malloc(num_cache_pages * sizeof(struct cache_page)); - if (!ctx->cache) - { - ERROR("Could not alloc compression cache\n"); - goto error; - } - - for (i =3D 0; i < num_cache_pages; i++) - { - ctx->cache[i].pfn =3D INVALID_PFN; - ctx->cache[i].page =3D ctx->cache_base + i * XC_PAGE_SIZE; - ctx->cache[i].prev =3D (i =3D=3D 0) ? NULL : &(ctx->cache[i - 1]); - ctx->cache[i].next =3D ((i+1) =3D=3D num_cache_pages)? NULL : - &(ctx->cache[i + 1]); - } - ctx->page_list_head =3D &(ctx->cache[0]); - ctx->page_list_tail =3D &(ctx->cache[num_cache_pages -1]); - ctx->dom_pfnlist_size =3D p2m_size; - - return ctx; -error: - xc_compression_free_context(xch, ctx); - return NULL; -} - -/* - * Local variables: - * mode: C - * c-file-style: "BSD" - * c-basic-offset: 4 - * tab-width: 4 - * indent-tabs-mode: nil - * End: - */ --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel