File libxc-sr-restore-pfns.patch of Package xen.33137

From: Olaf Hering <olaf@aepfle.de>
Date: Fri, 23 Oct 2020 14:36:45 +0200
Subject: libxc sr restore pfns

tools/guest: restore: move pfns array

Remove allocation from hotpath, move pfns array into preallocated space.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libxc/xc_sr_common.h  | 2 ++
 tools/libxc/xc_sr_restore.c | 6 ++----
 2 files changed, 4 insertions(+), 4 deletions(-)

--- xen-4.14.0-testing.orig/tools/libxc/xc_sr_common.h
+++ xen-4.14.0-testing/tools/libxc/xc_sr_common.h
@@ -225,6 +225,8 @@ struct xc_sr_save_arrays {
 };
 
 struct xc_sr_restore_arrays {
+    /* handle_page_data */
+    xen_pfn_t pfns[MAX_BATCH_SIZE];
 };
 
 struct xc_sr_context
--- xen-4.14.0-testing.orig/tools/libxc/xc_sr_restore.c
+++ xen-4.14.0-testing/tools/libxc/xc_sr_restore.c
@@ -315,7 +315,7 @@ static int handle_page_data(struct xc_sr
     unsigned int i, pages_of_data = 0;
     int rc = -1;
 
-    xen_pfn_t *pfns = NULL, pfn;
+    xen_pfn_t *pfns = ctx->restore.m->pfns, pfn;
     uint32_t *types = NULL, type;
 
     /*
@@ -363,9 +363,8 @@ static int handle_page_data(struct xc_sr
         goto err;
     }
 
-    pfns = malloc(pages->count * sizeof(*pfns));
     types = malloc(pages->count * sizeof(*types));
-    if ( !pfns || !types )
+    if ( !types )
     {
         ERROR("Unable to allocate enough memory for %u pfns",
               pages->count);
@@ -412,7 +411,6 @@ static int handle_page_data(struct xc_sr
                            &pages->pfn[pages->count]);
  err:
     free(types);
-    free(pfns);
 
     return rc;
 }
openSUSE Build Service is sponsored by