[20/20] tools/libxc: Restore CPUID/MSR data found in the migration stream
diff mbox series

Message ID 20200103130616.13724-7-andrew.cooper3@citrix.com
State New
Headers show
Series
  • Untitled series #223377
Related show

Commit Message

Andrew Cooper Jan. 3, 2020, 1:06 p.m. UTC
With libxl suitably adjusted, it is now safe to restore the CPUID/MSR data
directly from the migration stream.  Adjust the XGR_SDD_MISSING_* flags for
the static_data_done() callback appropriately.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Jackson <Ian.Jackson@citrix.com>
CC: Wei Liu <wl@xen.org>
---
 tools/libxc/xc_sr_common_x86.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Comments

Ian Jackson Jan. 14, 2020, 5:34 p.m. UTC | #1
Andrew Cooper writes ("[PATCH 20/20] tools/libxc: Restore CPUID/MSR data found in the migration stream"):
> With libxl suitably adjusted, it is now safe to restore the CPUID/MSR data
> directly from the migration stream.  Adjust the XGR_SDD_MISSING_* flags for
> the static_data_done() callback appropriately.

Subject to my comments earlier about (i) the unevenness of the
resulting libxc API and (ii) text about the compatibility plan,

Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>

Thanks,
Ian.

Patch
diff mbox series

diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c
index c3d1d30d91..5c5b3e7635 100644
--- a/tools/libxc/xc_sr_common_x86.c
+++ b/tools/libxc/xc_sr_common_x86.c
@@ -45,11 +45,31 @@  int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec)
 int x86_static_data_complete(struct xc_sr_context *ctx)
 {
     xc_interface *xch = ctx->xch;
+    uint32_t nr_leaves = 0, nr_msrs = 0;
+    uint32_t err_l = ~0, err_s = ~0, err_m = ~0;
     unsigned int missing = 0;
     int rc;
 
-    /* TODO - something useful. */
-    missing = XGR_SDD_MISSING_MSR | XGR_SDD_MISSING_CPUID;
+    if ( ctx->x86.restore.cpuid.ptr )
+        nr_leaves = ctx->x86.restore.cpuid.size / sizeof(xen_cpuid_leaf_t);
+    else
+        missing |= XGR_SDD_MISSING_CPUID;
+
+    if ( ctx->x86.restore.msr.ptr )
+        nr_msrs = ctx->x86.restore.msr.size / sizeof(xen_msr_entry_t);
+    else
+        missing |= XGR_SDD_MISSING_MSR;
+
+    if ( (nr_leaves || nr_msrs) &&
+         xc_set_domain_cpu_policy(xch, ctx->domid,
+                                  nr_leaves, ctx->x86.restore.cpuid.ptr,
+                                  nr_msrs,   ctx->x86.restore.msr.ptr,
+                                  &err_l, &err_s, &err_m) )
+    {
+        PERROR("Failed to set CPUID policy: leaf %08x, subleaf %08x, msr %08x",
+               err_l, err_s, err_m);
+        return -1;
+    }
 
     rc = ctx->restore.callbacks->static_data_done(
         missing, ctx->restore.callbacks->data);