[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 07/13] libx86: Introduce a helper to serialise msr_{domain, vcpu}_policy objects
From: Roger Pau Monné <roger.pau@xxxxxxxxxx> As with CPUID, the 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@xxxxxxxxxx> Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> --- CC: Jan Beulich <JBeulich@xxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> CC: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> --- tools/include/Makefile | 1 + tools/libxc/Makefile | 2 +- xen/common/libx86/Makefile | 1 + xen/common/libx86/libx86-private.h | 3 ++ xen/common/libx86/msr.c | 71 ++++++++++++++++++++++++++++++++++++++ xen/include/public/arch-x86/xen.h | 9 ++++- xen/include/xen/libx86/msr.h | 16 +++++++++ 7 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 xen/common/libx86/msr.c diff --git a/tools/include/Makefile b/tools/include/Makefile index fc99da9..1a0eae7 100644 --- a/tools/include/Makefile +++ b/tools/include/Makefile @@ -22,6 +22,7 @@ xen/.dir: ln -s ../xen-foreign xen/foreign ln -sf $(XEN_ROOT)/xen/include/acpi acpi ifeq ($(CONFIG_X86),y) + ln -sf $(XEN_ROOT)/xen/include/asm-x86 xen/asm ln -sf $(XEN_ROOT)/xen/include/xen/libx86 xen/libx86 endif touch $@ diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index f534d90..407a9d1 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -83,7 +83,7 @@ $(patsubst %.c,%.opic,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign # Add libx86 to the build vpath %.c ../../xen/common/libx86 -GUEST_SRCS-$(CONFIG_X86) += cpuid.c +GUEST_SRCS-$(CONFIG_X86) += cpuid.c msr.c # new domain builder GUEST_SRCS-y += xc_dom_core.c xc_dom_boot.c 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/libx86-private.h b/xen/common/libx86/libx86-private.h index a209850..e4ead1a 100644 --- a/xen/common/libx86/libx86-private.h +++ b/xen/common/libx86/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> #define MAX(x, y) ((x) > (y) ? (x) : (y)) diff --git a/xen/common/libx86/msr.c b/xen/common/libx86/msr.c new file mode 100644 index 0000000..46a3458 --- /dev/null +++ b/xen/common/libx86/msr.c @@ -0,0 +1,71 @@ +#include "libx86-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; +} + +/* + * Serialise msr_{domain,vcpu}_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_domain_policy *dp, + const struct msr_vcpu_policy *vp, + 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; \ + }) + + if ( dp ) + COPY_MSR(MSR_INTEL_PLATFORM_INFO, dp->plaform_info.raw); + + if ( vp ) + { + COPY_MSR(MSR_SPEC_CTRL, vp->spec_ctrl.raw); + COPY_MSR(MSR_INTEL_MISC_FEATURES_ENABLES, + vp->misc_features_enables.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/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 6b8b10b..8776378 100644 --- a/xen/include/xen/libx86/msr.h +++ b/xen/include/xen/libx86/msr.h @@ -2,6 +2,10 @@ #ifndef XEN_LIBX86_MSR_H #define XEN_LIBX86_MSR_H +#define MSR_MAX_SERIALISED_ENTRIES \ + (1 + /* msr_domain_policy */ \ + 2 /* msr_vcpu_policy*/ ) + /* MSR policy object for shared per-domain MSRs */ struct msr_domain_policy { @@ -45,6 +49,18 @@ struct msr_vcpu_policy } misc_features_enables; }; +#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 + +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); + #endif /* !XEN_LIBX86_MSR_H */ /* -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |