[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 2/5] libx86: Introduce a helper to serialise msr_policy objects
From: Roger Pau Monné <roger.pau@xxxxxxxxxx> 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@xxxxxxxxxx> Signed-off-by: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx> Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: Jan Beulich <jbeulich@xxxxxxxx> --- CC: Roger Pau Monné <roger.pau@xxxxxxxxxx> CC: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx> v2: * Rebase over the msr_{domain,vcpu}_policy rename * Only serialise msr_policy * Change to an array typedef for constness reasons v3: * Rebase over libx86's movement --- tools/libxc/Makefile | 2 +- xen/include/public/arch-x86/xen.h | 9 +++++- xen/include/xen/lib/x86/msr.h | 26 ++++++++++++++++++ xen/lib/x86/Makefile | 1 + xen/lib/x86/msr.c | 58 +++++++++++++++++++++++++++++++++++++++ xen/lib/x86/private.h | 3 ++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 xen/lib/x86/msr.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index 68bb367..44d9d09 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/lib/x86 -GUEST_SRCS-y += cpuid.c +GUEST_SRCS-y += cpuid.c msr.c endif # new domain builder diff --git a/xen/include/public/arch-x86/xen.h b/xen/include/public/arch-x86/xen.h index 7980f9e..8ed5904 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/lib/x86/msr.h b/xen/include/xen/lib/x86/msr.h index e6b13ad..e2cfbb1 100644 --- a/xen/include/xen/lib/x86/msr.h +++ b/xen/include/xen/lib/x86/msr.h @@ -2,6 +2,9 @@ #ifndef XEN_LIB_X86_MSR_H #define XEN_LIB_X86_MSR_H +/* Maximum number of MSRs written when serialising msr_policy. */ +#define MSR_MAX_SERIALISED_ENTRIES 1 + /* MSR policy object for shared per-domain MSRs */ struct msr_policy { @@ -22,6 +25,29 @@ 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 an msr_policy object into an array. + * + * @param policy The msr_policy to serialise. + * @param msrs The array of msrs to serialise into. + * @param nr_entries The number of entries in 'msrs'. + * @returns -errno + * + * Writes at most MSR_MAX_SERIALISED_ENTRIES. May fail with -ENOBUFS if the + * buffer array is too short. On success, nr_entries is updated with the + * actual number of msrs written. + */ +int x86_msr_copy_to_buffer(const struct msr_policy *policy, + msr_entry_buffer_t msrs, uint32_t *nr_entries); + #endif /* !XEN_LIB_X86_MSR_H */ /* diff --git a/xen/lib/x86/Makefile b/xen/lib/x86/Makefile index 3fb2e0b..2f9691e 100644 --- a/xen/lib/x86/Makefile +++ b/xen/lib/x86/Makefile @@ -1 +1,2 @@ obj-y += cpuid.o +obj-y += msr.o diff --git a/xen/lib/x86/msr.c b/xen/lib/x86/msr.c new file mode 100644 index 0000000..60fb567 --- /dev/null +++ b/xen/lib/x86/msr.c @@ -0,0 +1,58 @@ +#include "private.h" + +#include <xen/lib/x86/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/lib/x86/private.h b/xen/lib/x86/private.h index 83cb653..3ee99aa 100644 --- a/xen/lib/x86/private.h +++ b/xen/lib/x86/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) -- 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 |