[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] libxc/restore: Handle X86_{CPUID,MSR}_DATA records



commit 8baf4363e19c6f6e48b286b4643899564f98e620
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Dec 18 18:51:01 2019 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri May 29 17:33:03 2020 +0100

    libxc/restore: Handle X86_{CPUID,MSR}_DATA records
    
    For now, the data are just stashed, and discarded at the end.
    
    A future change will restore the data, once libxl has been adjusted to avoid
    clobbering the data.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxc/xc_sr_common.h          | 10 ++++++++++
 tools/libxc/xc_sr_common_x86.c      | 40 +++++++++++++++++++++++++++++++++++++
 tools/libxc/xc_sr_common_x86.h      | 14 +++++++++++++
 tools/libxc/xc_sr_restore_x86_hvm.c |  9 +++++++++
 tools/libxc/xc_sr_restore_x86_pv.c  |  9 +++++++++
 5 files changed, 82 insertions(+)

diff --git a/tools/libxc/xc_sr_common.h b/tools/libxc/xc_sr_common.h
index fd7fb67305..7742260690 100644
--- a/tools/libxc/xc_sr_common.h
+++ b/tools/libxc/xc_sr_common.h
@@ -296,6 +296,16 @@ struct xc_sr_context
     {
         struct /* x86 */
         {
+            /* Common save/restore data. */
+            union
+            {
+                struct
+                {
+                    /* X86_{CPUID,MSR}_DATA blobs for CPU Policy. */
+                    struct xc_sr_blob cpuid, msr;
+                } restore;
+            };
+
             struct /* x86 PV guest. */
             {
                 /* 4 or 8; 32 or 64 bit domain */
diff --git a/tools/libxc/xc_sr_common_x86.c b/tools/libxc/xc_sr_common_x86.c
index 011684df97..8980299e9a 100644
--- a/tools/libxc/xc_sr_common_x86.c
+++ b/tools/libxc/xc_sr_common_x86.c
@@ -42,6 +42,46 @@ int handle_x86_tsc_info(struct xc_sr_context *ctx, struct 
xc_sr_record *rec)
     return 0;
 }
 
+int handle_x86_cpuid_policy(struct xc_sr_context *ctx, struct xc_sr_record 
*rec)
+{
+    xc_interface *xch = ctx->xch;
+    int rc;
+
+    if ( rec->length == 0 ||
+         rec->length % sizeof(xen_cpuid_leaf_t) != 0 )
+    {
+        ERROR("X86_CPUID_POLICY size %u should be multiple of %zu",
+              rec->length, sizeof(xen_cpuid_leaf_t));
+        return -1;
+    }
+
+    rc = update_blob(&ctx->x86.restore.cpuid, rec->data, rec->length);
+    if ( rc )
+        ERROR("Unable to allocate %u bytes for X86_CPUID_POLICY", rec->length);
+
+    return rc;
+}
+
+int handle_x86_msr_policy(struct xc_sr_context *ctx, struct xc_sr_record *rec)
+{
+    xc_interface *xch = ctx->xch;
+    int rc;
+
+    if ( rec->length == 0 ||
+         rec->length % sizeof(xen_msr_entry_t) != 0 )
+    {
+        ERROR("X86_MSR_POLICY size %u should be multiple of %zu",
+              rec->length, sizeof(xen_cpuid_leaf_t));
+        return -1;
+    }
+
+    rc = update_blob(&ctx->x86.restore.msr, rec->data, rec->length);
+    if ( rc )
+        ERROR("Unable to allocate %u bytes for X86_MSR_POLICY", rec->length);
+
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxc/xc_sr_common_x86.h b/tools/libxc/xc_sr_common_x86.h
index ebc4355bd1..c458c1aa37 100644
--- a/tools/libxc/xc_sr_common_x86.h
+++ b/tools/libxc/xc_sr_common_x86.h
@@ -14,6 +14,20 @@ int write_x86_tsc_info(struct xc_sr_context *ctx);
  */
 int handle_x86_tsc_info(struct xc_sr_context *ctx, struct xc_sr_record *rec);
 
+/*
+ * Parses an X86_CPUID_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_cpuid_policy(struct xc_sr_context *ctx,
+                            struct xc_sr_record *rec);
+
+/*
+ * Parses an X86_MSR_POLICY record and stashes the content for application
+ * when a STATIC_DATA_END record is encountered.
+ */
+int handle_x86_msr_policy(struct xc_sr_context *ctx,
+                          struct xc_sr_record *rec);
+
 #endif
 /*
  * Local variables:
diff --git a/tools/libxc/xc_sr_restore_x86_hvm.c 
b/tools/libxc/xc_sr_restore_x86_hvm.c
index adbdf1ae5f..1704d524b4 100644
--- a/tools/libxc/xc_sr_restore_x86_hvm.c
+++ b/tools/libxc/xc_sr_restore_x86_hvm.c
@@ -181,6 +181,12 @@ static int x86_hvm_process_record(struct xc_sr_context 
*ctx,
     case REC_TYPE_HVM_PARAMS:
         return handle_hvm_params(ctx, rec);
 
+    case REC_TYPE_X86_CPUID_POLICY:
+        return handle_x86_cpuid_policy(ctx, rec);
+
+    case REC_TYPE_X86_MSR_POLICY:
+        return handle_x86_msr_policy(ctx, rec);
+
     default:
         return RECORD_NOT_PROCESSED;
     }
@@ -237,6 +243,9 @@ static int x86_hvm_cleanup(struct xc_sr_context *ctx)
 {
     free(ctx->x86.hvm.restore.context.ptr);
 
+    free(ctx->x86.restore.cpuid.ptr);
+    free(ctx->x86.restore.msr.ptr);
+
     return 0;
 }
 
diff --git a/tools/libxc/xc_sr_restore_x86_pv.c 
b/tools/libxc/xc_sr_restore_x86_pv.c
index 0adfcdcdda..a3d85d517d 100644
--- a/tools/libxc/xc_sr_restore_x86_pv.c
+++ b/tools/libxc/xc_sr_restore_x86_pv.c
@@ -1102,6 +1102,12 @@ static int x86_pv_process_record(struct xc_sr_context 
*ctx,
     case REC_TYPE_X86_TSC_INFO:
         return handle_x86_tsc_info(ctx, rec);
 
+    case REC_TYPE_X86_CPUID_POLICY:
+        return handle_x86_cpuid_policy(ctx, rec);
+
+    case REC_TYPE_X86_MSR_POLICY:
+        return handle_x86_msr_policy(ctx, rec);
+
     default:
         return RECORD_NOT_PROCESSED;
     }
@@ -1173,6 +1179,9 @@ static int x86_pv_cleanup(struct xc_sr_context *ctx)
     if ( ctx->x86.pv.m2p )
         munmap(ctx->x86.pv.m2p, ctx->x86.pv.nr_m2p_frames * PAGE_SIZE);
 
+    free(ctx->x86.restore.cpuid.ptr);
+    free(ctx->x86.restore.msr.ptr);
+
     return 0;
 }
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.