[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v2 10/13] libx86: introduce a helper to deserialise msr_policy objects
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> --- 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@xxxxxxxxxx> v2: * Rebase over the msr_{domain,vcpu}_policy rename * Only deserialse msr_policy * Expand boundary justifications --- xen/common/libx86/msr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ xen/include/xen/libx86/msr.h | 10 +++++++++ 2 files changed, 61 insertions(+) diff --git a/xen/common/libx86/msr.c b/xen/common/libx86/msr.c index 71c8e9a..0912ace 100644 --- a/xen/common/libx86/msr.c +++ b/xen/common/libx86/msr.c @@ -45,6 +45,57 @@ int x86_msr_copy_to_buffer(const struct msr_policy *p, return 0; } +int x86_msr_copy_from_buffer(struct msr_policy *p, + const msr_entry_buffer_t msrs, uint32_t nr_msrs, + uint32_t *err_msr) +{ + unsigned int i; + xen_msr_entry_t data; + + /* + * A well formed caller is expected pass an array with entries in order, + * and without any repetitions. However, due to per-vendor differences, + * and in the case of upgrade or levelled scenarios, we typically expect + * fewer than MAX entries to be passed. + * + * Detecting repeated entries is prohibitively complicated, so we don't + * bother. That said, one way or another if more than MAX entries are + * passed, something is wrong. + */ + 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_INTEL_PLATFORM_INFO: + if ( data.val > ~0u ) + goto err; + + p->plaform_info.raw = data.val; + break; + + default: + goto err; + } + } + + return 0; + + err: + if ( err_msr ) + *err_msr = data.idx; + + return -EINVAL; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/libx86/msr.h b/xen/include/xen/libx86/msr.h index 2e4acd4..d71ad78 100644 --- a/xen/include/xen/libx86/msr.h +++ b/xen/include/xen/libx86/msr.h @@ -42,6 +42,16 @@ typedef xen_msr_entry_t msr_entry_buffer_t[]; int x86_msr_copy_to_buffer(const struct msr_policy *p, msr_entry_buffer_t msrs, uint32_t *nr_entries_p); +/* + * Copy MSR data from a buffer, filling an msr_policy object. MSR indicies + * are checked for being in range, but no content validation is performed for + * in-range MSRs. On an error, the optional err_* pointer may help identify + * where the issue lies. + */ +int x86_msr_copy_from_buffer(struct msr_policy *dp, + 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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |