All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Sergey Dyasli" <sergey.dyasli@citrix.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 12/13] libx86: introduce a helper to deserialize MSR policies
Date: Tue, 3 Jul 2018 21:55:25 +0100	[thread overview]
Message-ID: <1530651326-5320-13-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1530651326-5320-1-git-send-email-andrew.cooper3@citrix.com>

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

Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
 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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-07-03 20:55 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 20:55 [PATCH 00/13] x86: CPUID and MSR policy marshalling support Andrew Cooper
2018-07-03 20:55 ` [PATCH 01/13] libx86: Introduce libx86/cpuid.h Andrew Cooper
2018-07-04  6:54   ` Wei Liu
2018-07-04  8:21   ` Jan Beulich
2018-07-04 12:03     ` Andrew Cooper
2018-07-04 13:57       ` Jan Beulich
2018-07-06  1:35         ` Doug Goldstein
2018-07-06  8:07           ` Jan Beulich
2018-07-03 20:55 ` [PATCH 02/13] libx86: generate cpuid-autogen.h in the libx86 include dir Andrew Cooper
2018-07-04  7:03   ` Wei Liu
2018-07-04  8:33   ` Jan Beulich
2018-07-03 20:55 ` [PATCH 03/13] libx86: Share struct cpuid_policy with userspace Andrew Cooper
2018-07-04  7:08   ` Wei Liu
2018-07-04  8:36   ` Jan Beulich
2018-07-03 20:55 ` [PATCH 04/13] libx86: introduce a libx86 shared library Andrew Cooper
2018-07-04  7:20   ` Wei Liu
2018-07-04  8:42   ` Jan Beulich
2018-07-04 15:48     ` Andrew Cooper
2018-07-03 20:55 ` [PATCH 05/13] libx86: Introduce libx86/msr.h and share msr_{domain, vcpu}_policy with userspace Andrew Cooper
2018-07-04  7:21   ` Wei Liu
2018-07-04  8:43   ` Jan Beulich
2018-07-03 20:55 ` [PATCH 06/13] libx86: Introduce a helper to serialise a cpuid_policy object Andrew Cooper
2018-07-04  8:42   ` Wei Liu
2018-07-04  8:51     ` Jan Beulich
2018-07-04 16:23       ` Andrew Cooper
2018-07-05  8:09         ` Wei Liu
2018-07-05  8:40         ` Jan Beulich
2018-07-05 13:39           ` Andrew Cooper
2018-07-05 14:05             ` Jan Beulich
2018-07-04  9:01   ` Jan Beulich
2018-07-04 16:46     ` Andrew Cooper
2018-07-05  8:11       ` Wei Liu
2018-07-05 10:21         ` Andrew Cooper
2018-07-05  8:46       ` Jan Beulich
2018-07-05 13:34         ` Andrew Cooper
2018-07-03 20:55 ` [PATCH 07/13] libx86: Introduce a helper to serialise msr_{domain, vcpu}_policy objects Andrew Cooper
2018-07-04  9:16   ` Jan Beulich
2018-07-04 16:56     ` Andrew Cooper
2018-07-05  8:49       ` Jan Beulich
2018-07-03 20:55 ` [PATCH 08/13] x86: Collect policies together into groups Andrew Cooper
2018-07-04  9:22   ` Jan Beulich
2018-07-04 17:15     ` Andrew Cooper
2018-07-05  8:54       ` Jan Beulich
2018-07-03 20:55 ` [PATCH 09/13] x86/sysctl: Implement XEN_SYSCTL_get_cpumsr_policy Andrew Cooper
2018-07-04  9:43   ` Jan Beulich
2018-07-04 17:57     ` Andrew Cooper
2018-07-05  9:08       ` Jan Beulich
2018-07-05 14:08         ` Andrew Cooper
2018-07-05 14:45           ` Jan Beulich
2018-07-03 20:55 ` [PATCH 10/13] x86/domctl: Implement XEN_DOMCTL_get_cpumsr_policy Andrew Cooper
2018-07-04  9:48   ` Jan Beulich
2018-07-05 14:23   ` Sergey Dyasli
2018-07-03 20:55 ` [PATCH 11/13] libx86: Introduce a helper to deserialise a cpuid_policy object Andrew Cooper
2018-07-04  9:49   ` Jan Beulich
2018-07-03 20:55 ` Andrew Cooper [this message]
2018-07-03 20:55 ` [PATCH 13/13] x86/domctl: Implement XEN_DOMCTL_set_cpumsr_policy Andrew Cooper
2018-07-04 10:16   ` Jan Beulich
2018-07-04 18:47     ` Andrew Cooper
2018-07-05  9:28       ` Jan Beulich
2018-07-05 17:55         ` Andrew Cooper
2018-07-06  7:51           ` Jan Beulich
2018-07-06 10:02             ` Andrew Cooper
2018-07-04 10:18   ` Wei Liu
2018-07-04 10:33     ` Andrew Cooper
2018-07-04  8:17 ` [PATCH 00/13] x86: CPUID and MSR policy marshalling support Jan Beulich
2018-07-04 10:40   ` Andrew Cooper
2018-07-04 10:44     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1530651326-5320-13-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=sergey.dyasli@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.