[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen staging] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy



commit ad8e6232d5897eab052596389ccb8eb8f1d850a1
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed May 22 18:39:23 2019 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Thu May 23 15:54:05 2019 +0100

    libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
    
    This avoids opencoding the slightly-awkward logic.  More uses of these
    wrappers will be introduced shortly.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/xstate.c           |  8 ++------
 xen/include/xen/lib/x86/cpuid.h | 12 ++++++++++++
 xen/lib/x86/cpuid.c             |  3 +--
 3 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 3da609a6b0..3293ef834f 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
 int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
                     const struct xsave_hdr *hdr)
 {
-    const struct cpuid_policy *cp = d->arch.cpuid;
-    uint64_t xcr0_max =
-        ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+    uint64_t xcr0_max = cpuid_policy_xcr0_max(d->arch.cpuid);
     unsigned int i;
 
     if ( (hdr->xstate_bv & ~xcr0_accum) ||
@@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, 
uint64_t xcr0_accum,
 int handle_xsetbv(u32 index, u64 new_bv)
 {
     struct vcpu *curr = current;
-    const struct cpuid_policy *cp = curr->domain->arch.cpuid;
-    uint64_t xcr0_max =
-        ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+    uint64_t xcr0_max = cpuid_policy_xcr0_max(curr->domain->arch.cpuid);
     u64 mask;
 
     if ( index != XCR_XFEATURE_ENABLED_MASK )
diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h
index 252d2c978d..ed7d7b41fe 100644
--- a/xen/include/xen/lib/x86/cpuid.h
+++ b/xen/include/xen/lib/x86/cpuid.h
@@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
     p->feat._7a1  = fs[FEATURESET_7a1];
 }
 
+static inline uint64_t cpuid_policy_xcr0_max(const struct cpuid_policy *p)
+{
+    return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
+}
+
+static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
+{
+    uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
+
+    return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
+}
+
 const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature);
 
 /**
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7967..74c5b18ac7 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -144,8 +144,7 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy *p)
         cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]);
         cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]);
 
-        xstates  = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 
32);
-        xstates |=            (p->xstate.xcr0_low  | p->xstate.xss_low);
+        xstates = cpuid_policy_xstates(p);
 
         for ( i = 2; i < min_t(unsigned int, 63,
                                ARRAY_SIZE(p->xstate.raw)); ++i )
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.