From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Sergey Dyasli" <sergey.dyasli@citrix.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Ian Jackson" <Ian.Jackson@eu.citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v2 08/13] libx86: Introduce a helper to serialise msr_policy objects
Date: Fri, 13 Jul 2018 21:03:09 +0100 [thread overview]
Message-ID: <1531512194-6865-9-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1531512194-6865-1-git-send-email-andrew.cooper3@citrix.com>
From: Roger Pau Monné <roger.pau@citrix.com>
As with CPUID, an architectural form is used for representing the MSR data.
It is expected not to change moving forwards, but does have a 32 bit field
(currently reserved) which can be used compatibly if needs be.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Sergey Dyasli <sergey.dyasli@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
v2:
* Rebase over the msr_{domain,vcpu}_policy rename
* Only serialise msr_policy
* Change to an array typedef for constness reasons
---
tools/libxc/Makefile | 2 +-
xen/common/libx86/Makefile | 1 +
xen/common/libx86/msr.c | 56 +++++++++++++++++++++++++++++++++++++++
xen/common/libx86/private.h | 3 +++
xen/include/public/arch-x86/xen.h | 9 ++++++-
xen/include/xen/libx86/msr.h | 20 ++++++++++++++
6 files changed, 89 insertions(+), 2 deletions(-)
create mode 100644 xen/common/libx86/msr.c
diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index cd4225c..904e026 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -83,7 +83,7 @@ $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
ifeq ($(CONFIG_X86),y) # Add libx86 to the build
vpath %.c ../../xen/common/libx86
-GUEST_SRCS-y += cpuid.c
+GUEST_SRCS-y += cpuid.c msr.c
endif
# new domain builder
diff --git a/xen/common/libx86/Makefile b/xen/common/libx86/Makefile
index 3fb2e0b..2f9691e 100644
--- a/xen/common/libx86/Makefile
+++ b/xen/common/libx86/Makefile
@@ -1 +1,2 @@
obj-y += cpuid.o
+obj-y += msr.o
diff --git a/xen/common/libx86/msr.c b/xen/common/libx86/msr.c
new file mode 100644
index 0000000..71c8e9a
--- /dev/null
+++ b/xen/common/libx86/msr.c
@@ -0,0 +1,56 @@
+#include "private.h"
+
+#include <xen/libx86/msr.h>
+
+/*
+ * Copy a single MSR into the provided msr_entry_buffer_t buffer, performing a
+ * boundary check against the buffer size.
+ */
+static int copy_msr_to_buffer(uint32_t idx, uint64_t val,
+ msr_entry_buffer_t msrs,
+ uint32_t *curr_entry, const uint32_t nr_entries)
+{
+ const xen_msr_entry_t ent = { .idx = idx, .val = val };
+
+ if ( *curr_entry == nr_entries )
+ return -ENOBUFS;
+
+ if ( copy_to_buffer_offset(msrs, *curr_entry, &ent, 1) )
+ return -EFAULT;
+
+ ++*curr_entry;
+
+ return 0;
+}
+
+int x86_msr_copy_to_buffer(const struct msr_policy *p,
+ msr_entry_buffer_t msrs, uint32_t *nr_entries_p)
+{
+ const uint32_t nr_entries = *nr_entries_p;
+ uint32_t curr_entry = 0;
+
+#define COPY_MSR(idx, val) \
+ ({ int ret; \
+ if ( (ret = copy_msr_to_buffer( \
+ idx, val, msrs, &curr_entry, nr_entries)) ) \
+ return ret; \
+ })
+
+ COPY_MSR(MSR_INTEL_PLATFORM_INFO, p->plaform_info.raw);
+
+#undef COPY_MSR
+
+ *nr_entries_p = curr_entry;
+
+ return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
diff --git a/xen/common/libx86/private.h b/xen/common/libx86/private.h
index 5f59961..e874fb6 100644
--- a/xen/common/libx86/private.h
+++ b/xen/common/libx86/private.h
@@ -9,6 +9,7 @@
#include <xen/types.h>
#include <asm/guest_access.h>
+#include <asm/msr-index.h>
#define copy_to_buffer_offset copy_to_guest_offset
@@ -19,6 +20,8 @@
#include <stdbool.h>
#include <stddef.h>
+#include <xen/asm/msr-index.h>
+
#include <xen-tools/libs.h>
static inline bool test_bit(unsigned int bit, const void *vaddr)
diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h
index f3bdd83..55a149f 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -315,7 +315,7 @@ struct xen_arch_domainconfig {
#endif
/*
- * Representations of architectural CPUID information. Used as the
+ * Representations of architectural CPUID and MSR information. Used as the
* serialised version of Xen's internal representation.
*/
typedef struct xen_cpuid_leaf {
@@ -325,6 +325,13 @@ typedef struct xen_cpuid_leaf {
} xen_cpuid_leaf_t;
DEFINE_XEN_GUEST_HANDLE(xen_cpuid_leaf_t);
+typedef struct xen_msr_entry {
+ uint32_t idx;
+ uint32_t flags; /* Reserved MBZ. */
+ uint64_t val;
+} xen_msr_entry_t;
+DEFINE_XEN_GUEST_HANDLE(xen_msr_entry_t);
+
#endif /* !__ASSEMBLY__ */
/*
diff --git a/xen/include/xen/libx86/msr.h b/xen/include/xen/libx86/msr.h
index b8b1751..2e4acd4 100644
--- a/xen/include/xen/libx86/msr.h
+++ b/xen/include/xen/libx86/msr.h
@@ -2,6 +2,9 @@
#ifndef XEN_LIBX86_MSR_H
#define XEN_LIBX86_MSR_H
+/* Maximum number of MSRs written when serialising msr_domain_policy. */
+#define MSR_MAX_SERIALISED_ENTRIES 1
+
/* MSR policy object for shared per-domain MSRs */
struct msr_policy
{
@@ -22,6 +25,23 @@ struct msr_policy
} plaform_info;
};
+#ifdef __XEN__
+#include <public/arch-x86/xen.h>
+typedef XEN_GUEST_HANDLE_64(xen_msr_entry_t) msr_entry_buffer_t;
+#else
+#include <xen/arch-x86/xen.h>
+typedef xen_msr_entry_t msr_entry_buffer_t[];
+#endif
+
+/*
+ * Serialise a msr_policy object into an array. Writes at most
+ * MSR_MAX_SERIALISED_ENTRIES. Returns -ENOBUFS if the buffer array is too
+ * short. On success, nr_entries_p is updated with the actual number of
+ * leaves written.
+ */
+int x86_msr_copy_to_buffer(const struct msr_policy *p,
+ msr_entry_buffer_t msrs, uint32_t *nr_entries_p);
+
#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
next prev parent reply other threads:[~2018-07-13 20:03 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 20:03 [PATCH v2 00/13] x86: CPUID and MSR policy marshalling support Andrew Cooper
2018-07-13 20:03 ` [PATCH v2 01/13] x86/msr: Drop stale comment for vcpu_msrs.spec_ctrl Andrew Cooper
2018-07-16 7:21 ` Jan Beulich
2018-07-16 9:37 ` Roger Pau Monné
2018-07-16 11:02 ` Andrew Cooper
2018-07-13 20:03 ` [PATCH v2 02/13] libx86: Introduce libx86/cpuid.h Andrew Cooper
2018-07-16 9:23 ` Jan Beulich
2018-07-16 10:22 ` Andrew Cooper
2018-07-16 10:51 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 03/13] libx86: generate cpuid-autogen.h in the libx86 include dir Andrew Cooper
2018-07-16 9:31 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 04/13] libx86: Share struct cpuid_policy with userspace Andrew Cooper
2018-07-16 9:38 ` Jan Beulich
2018-07-16 9:51 ` Andrew Cooper
2018-07-16 10:04 ` Jan Beulich
2018-07-16 10:16 ` Andrew Cooper
2018-07-16 10:24 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 05/13] libx86: introduce a libx86 shared library Andrew Cooper
2018-07-16 9:02 ` Wei Liu
2018-07-16 10:17 ` Jan Beulich
2018-07-16 10:35 ` Andrew Cooper
2018-07-16 10:52 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 06/13] libx86: Introduce libx86/msr.h and share msr_policy with userspace Andrew Cooper
2018-07-16 9:41 ` Roger Pau Monné
2018-07-16 10:19 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 07/13] libx86: Introduce a helper to serialise cpuid_policy objects Andrew Cooper
2018-07-16 9:18 ` Wei Liu
2018-07-16 9:45 ` Jan Beulich
2018-07-16 10:39 ` Andrew Cooper
2018-07-16 10:55 ` Jan Beulich
2018-07-16 10:45 ` Jan Beulich
2018-07-17 10:02 ` Andrew Cooper
2018-07-17 11:58 ` Jan Beulich
2018-07-13 20:03 ` Andrew Cooper [this message]
2018-07-16 9:24 ` [PATCH v2 08/13] libx86: Introduce a helper to serialise msr_policy objects Wei Liu
2018-07-16 10:47 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 09/13] libx86: Introduce a helper to deserialise cpuid_policy objects Andrew Cooper
2018-07-16 9:57 ` Wei Liu
2018-07-17 10:09 ` Andrew Cooper
2018-07-13 20:03 ` [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects Andrew Cooper
2018-07-16 10:07 ` Wei Liu
2018-07-16 11:36 ` Jan Beulich
2018-07-17 10:17 ` Andrew Cooper
2018-07-17 12:01 ` Jan Beulich
2018-07-17 16:06 ` Andrew Cooper
2018-07-17 16:23 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 11/13] x86: Introduce struct cpu_policy to refer to a group of individual policies Andrew Cooper
2018-07-16 9:55 ` Roger Pau Monné
2018-07-16 10:32 ` Wei Liu
2018-07-16 12:04 ` Jan Beulich
2018-07-16 12:16 ` Andrew Cooper
2018-07-16 12:29 ` Jan Beulich
2018-07-16 13:15 ` Andrew Cooper
2018-07-16 13:23 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 12/13] x86/sysctl: Implement XEN_SYSCTL_get_cpu_policy Andrew Cooper
2018-07-16 10:16 ` Roger Pau Monné
2018-07-16 10:58 ` Andrew Cooper
2018-07-16 11:04 ` Jan Beulich
2018-07-16 11:54 ` Jan Beulich
2018-07-17 16:50 ` Andrew Cooper
2018-07-18 6:45 ` Jan Beulich
2018-07-13 20:03 ` [PATCH v2 13/13] x86/domctl: Implement XEN_DOMCTL_get_cpu_policy Andrew Cooper
2018-07-16 10:26 ` Roger Pau Monné
2018-07-17 17:08 ` Andrew Cooper
2018-07-16 12:00 ` Jan Beulich
2018-07-30 2:14 ` Chao Gao
2018-08-17 21:22 ` Daniel De Graaf
2018-07-30 2:46 ` [PATCH v2 00/13] x86: CPUID and MSR policy marshalling support Chao Gao
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=1531512194-6865-9-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=sergey.dyasli@citrix.com \
--cc=wei.liu2@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).