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

[Xen-devel] [PATCH 12/13] libx86: introduce a helper to deserialize MSR policies



From: Roger Pau Monné <roger.pau@xxxxxxxxxx>

Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 xen/common/libx86/msr.c      | 63 ++++++++++++++++++++++++++++++++++++++++++++
 xen/include/xen/libx86/msr.h |  4 +++
 2 files changed, 67 insertions(+)

diff --git a/xen/common/libx86/msr.c b/xen/common/libx86/msr.c
index 46a3458..13fb660 100644
--- a/xen/common/libx86/msr.c
+++ b/xen/common/libx86/msr.c
@@ -61,6 +61,69 @@ int x86_msr_copy_to_buffer(const struct msr_domain_policy 
*dp,
 }
 
 /*
+ * Copy MSR data from a buffer, filling optionally msr_domain_policy and
+ * msr_vcpu_policy objects.  MSR indicies are checked for being in range, but
+ * no content validation is performed for in-range MSRs.
+ */
+int x86_msr_copy_from_buffer(struct msr_domain_policy *dp,
+                             struct msr_vcpu_policy *vp,
+                             const msr_entry_buffer_t msrs, uint32_t nr_msrs,
+                             uint32_t *err_msr)
+{
+    unsigned int i;
+    xen_msr_entry_t data;
+
+    if ( nr_msrs > MSR_MAX_SERIALISED_ENTRIES )
+        return -E2BIG;
+
+    for ( i = 0; i < nr_msrs; i++ )
+    {
+        if ( copy_from_buffer_offset(&data, msrs, i, 1) )
+            return -EFAULT;
+
+        if ( data.flags ) /* .flags MBZ */
+            goto err;
+
+        switch ( data.idx )
+        {
+        case MSR_SPEC_CTRL:
+            if ( data.val > ~0u )
+                goto err;
+
+            if ( vp )
+                vp->spec_ctrl.raw = data.val;
+            break;
+
+        case MSR_INTEL_PLATFORM_INFO:
+            if ( data.val > ~0u )
+                goto err;
+
+            if ( dp )
+                dp->plaform_info.raw = data.val;
+            break;
+
+        case MSR_INTEL_MISC_FEATURES_ENABLES:
+            if ( data.val > ~0u )
+                goto err;
+
+            if ( vp )
+                vp->misc_features_enables.raw = data.val;
+            break;
+
+        default:
+            goto err;
+        }
+    }
+
+    return 0;
+
+ err:
+    if ( err_msr )
+        *err_msr = data.idx;
+    return -EINVAL;
+}
+
+/*
  * Local variables:
  * mode: C
  * c-file-style: "BSD"
diff --git a/xen/include/xen/libx86/msr.h b/xen/include/xen/libx86/msr.h
index 8776378..827eb3f 100644
--- a/xen/include/xen/libx86/msr.h
+++ b/xen/include/xen/libx86/msr.h
@@ -60,6 +60,10 @@ typedef xen_msr_entry_t *msr_entry_buffer_t;
 int x86_msr_copy_to_buffer(const struct msr_domain_policy *dp,
                            const struct msr_vcpu_policy *vp,
                            msr_entry_buffer_t msrs, uint32_t *nr_entries_p);
+int x86_msr_copy_from_buffer(struct msr_domain_policy *dp,
+                             struct msr_vcpu_policy *vp,
+                             const msr_entry_buffer_t msrs, uint32_t nr_msrs,
+                             uint32_t *err_msr);
 
 #endif /* !XEN_LIBX86_MSR_H */
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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