[xen staging] libx86: introduce a libx86 shared library

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[xen staging] libx86: introduce a libx86 shared library

patchbot
commit fea2fab9635613d5be83482da5d79160ef928941
Author:     Roger Pau Monné <[hidden email]>
AuthorDate: Thu Jun 21 15:35:48 2018 +0100
Commit:     Andrew Cooper <[hidden email]>
CommitDate: Thu Jul 19 19:31:31 2018 +0100

    libx86: introduce a libx86 shared library
   
    Move x86_cpuid_lookup_deep_deps() into the shared library, removing the
    individual copies from the hypervisor and libxc respectively.
   
    Signed-off-by: Roger Pau Monné <[hidden email]>
    Signed-off-by: Andrew Cooper <[hidden email]>
    Reviewed-by: Wei Liu <[hidden email]>
    Acked-by: Jan Beulich <[hidden email]>
---
 tools/libxc/Makefile            |  6 ++++++
 tools/libxc/include/xenctrl.h   |  1 -
 tools/libxc/xc_cpuid_x86.c      | 29 +--------------------------
 xen/Rules.mk                    |  1 +
 xen/arch/x86/cpu/common.c       |  2 +-
 xen/arch/x86/cpuid.c            | 32 +-----------------------------
 xen/include/asm-x86/cpuid.h     |  2 --
 xen/include/xen/lib/x86/cpuid.h |  2 ++
 xen/lib/Makefile                |  1 +
 xen/lib/x86/Makefile            |  1 +
 xen/lib/x86/cpuid.c             | 44 +++++++++++++++++++++++++++++++++++++++++
 xen/lib/x86/private.h           | 38 +++++++++++++++++++++++++++++++++++
 12 files changed, 96 insertions(+), 63 deletions(-)

diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile
index ca2b20345e..68bb3679fd 100644
--- a/tools/libxc/Makefile
+++ b/tools/libxc/Makefile
@@ -80,6 +80,12 @@ GUEST_SRCS-y += $(ELF_SRCS-y)
 $(patsubst %.c,%.o,$(ELF_SRCS-y)): CFLAGS += -Wno-pointer-sign
 $(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
+endif
+
 # new domain builder
 GUEST_SRCS-y                 += xc_dom_core.c xc_dom_boot.c
 GUEST_SRCS-y                 += xc_dom_elfloader.c
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 5520c942d1..dd7d8a9724 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2564,7 +2564,6 @@ enum xc_static_cpu_featuremask {
     XC_FEATUREMASK_DEEP_FEATURES,
 };
 const uint32_t *xc_get_static_cpu_featuremask(enum xc_static_cpu_featuremask);
-const uint32_t *xc_get_feature_deep_deps(uint32_t feature);
 
 #endif
 
diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
index 6e02792a15..483b1328e4 100644
--- a/tools/libxc/xc_cpuid_x86.c
+++ b/tools/libxc/xc_cpuid_x86.c
@@ -131,33 +131,6 @@ const uint32_t *xc_get_static_cpu_featuremask(
     }
 }
 
-const uint32_t *xc_get_feature_deep_deps(uint32_t feature)
-{
-    static const struct {
-        uint32_t feature;
-        uint32_t fs[FEATURESET_NR_ENTRIES];
-    } deep_deps[] = INIT_DEEP_DEPS;
-
-    unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
-
-    BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
-
-    /* deep_deps[] is sorted.  Perform a binary search. */
-    while ( start < end )
-    {
-        unsigned int mid = start + ((end - start) / 2);
-
-        if ( deep_deps[mid].feature > feature )
-            end = mid;
-        else if ( deep_deps[mid].feature < feature )
-            start = mid + 1;
-        else
-            return deep_deps[mid].fs;
-    }
-
-    return NULL;
-}
-
 struct cpuid_domain_info
 {
     enum
@@ -677,7 +650,7 @@ static void sanitise_featureset(struct cpuid_domain_info *info)
         const uint32_t *dfs;
 
         if ( !test_bit(b, disabled_features) ||
-             !(dfs = xc_get_feature_deep_deps(b)) )
+             !(dfs = x86_cpuid_lookup_deep_deps(b)) )
              continue;
 
         for ( i = 0; i < ARRAY_SIZE(disabled_features); ++i )
diff --git a/xen/Rules.mk b/xen/Rules.mk
index 5337e206ee..47c954425d 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -36,6 +36,7 @@ TARGET := $(BASEDIR)/xen
 # Note that link order matters!
 ALL_OBJS-y               += $(BASEDIR)/common/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/drivers/built_in.o
+ALL_OBJS-$(CONFIG_X86)   += $(BASEDIR)/lib/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/xsm/built_in.o
 ALL_OBJS-y               += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
 ALL_OBJS-$(CONFIG_CRYPTO)   += $(BASEDIR)/crypto/built_in.o
diff --git a/xen/arch/x86/cpu/common.c b/xen/arch/x86/cpu/common.c
index 4d768d4ff6..057859ab14 100644
--- a/xen/arch/x86/cpu/common.c
+++ b/xen/arch/x86/cpu/common.c
@@ -63,7 +63,7 @@ void __init setup_clear_cpu_cap(unsigned int cap)
        __builtin_return_address(0), cap);
 
  __clear_bit(cap, boot_cpu_data.x86_capability);
- dfs = lookup_deep_deps(cap);
+ dfs = x86_cpuid_lookup_deep_deps(cap);
 
  if (!dfs)
  return;
diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c
index 5f093a9b30..f160389f19 100644
--- a/xen/arch/x86/cpuid.c
+++ b/xen/arch/x86/cpuid.c
@@ -97,7 +97,7 @@ static void sanitise_featureset(uint32_t *fs)
     for_each_set_bit(i, (void *)disabled_features,
                      sizeof(disabled_features) * 8)
     {
-        const uint32_t *dfs = lookup_deep_deps(i);
+        const uint32_t *dfs = x86_cpuid_lookup_deep_deps(i);
         unsigned int j;
 
         ASSERT(dfs); /* deep_features[] should guarentee this. */
@@ -548,36 +548,6 @@ bool recheck_cpu_features(unsigned int cpu)
     return okay;
 }
 
-const uint32_t *lookup_deep_deps(uint32_t feature)
-{
-    static const struct {
-        uint32_t feature;
-        uint32_t fs[FSCAPINTS];
-    } deep_deps[] = INIT_DEEP_DEPS;
-    unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
-
-    BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
-
-    /* Fast early exit. */
-    if ( !test_bit(feature, deep_features) )
-        return NULL;
-
-    /* deep_deps[] is sorted.  Perform a binary search. */
-    while ( start < end )
-    {
-        unsigned int mid = start + ((end - start) / 2);
-
-        if ( deep_deps[mid].feature > feature )
-            end = mid;
-        else if ( deep_deps[mid].feature < feature )
-            start = mid + 1;
-        else
-            return deep_deps[mid].fs;
-    }
-
-    return NULL;
-}
-
 void recalculate_cpuid_policy(struct domain *d)
 {
     struct cpuid_policy *p = d->arch.cpuid;
diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h
index 30e5453d81..00de592c39 100644
--- a/xen/include/asm-x86/cpuid.h
+++ b/xen/include/asm-x86/cpuid.h
@@ -17,8 +17,6 @@ extern const uint32_t special_features[FSCAPINTS];
 
 void init_guest_cpuid(void);
 
-const uint32_t *lookup_deep_deps(uint32_t feature);
-
 /*
  * Expected levelling capabilities (given cpuid vendor/family information),
  * and levelling capabilities actually available (given MSR probing).
diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h
index fa908b77b0..93ada23ecb 100644
--- a/xen/include/xen/lib/x86/cpuid.h
+++ b/xen/include/xen/lib/x86/cpuid.h
@@ -228,6 +228,8 @@ static inline void cpuid_featureset_to_policy(
     p->feat._7d0  = fs[FEATURESET_7d0];
 }
 
+const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature);
+
 #endif /* !XEN_LIB_X86_CPUID_H */
 
 /*
diff --git a/xen/lib/Makefile b/xen/lib/Makefile
new file mode 100644
index 0000000000..dcdb759313
--- /dev/null
+++ b/xen/lib/Makefile
@@ -0,0 +1 @@
+subdir-$(CONFIG_X86) += x86
diff --git a/xen/lib/x86/Makefile b/xen/lib/x86/Makefile
new file mode 100644
index 0000000000..3fb2e0bd8f
--- /dev/null
+++ b/xen/lib/x86/Makefile
@@ -0,0 +1 @@
+obj-y += cpuid.o
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
new file mode 100644
index 0000000000..a63e42b166
--- /dev/null
+++ b/xen/lib/x86/cpuid.c
@@ -0,0 +1,44 @@
+#include "private.h"
+
+#include <xen/lib/x86/cpuid.h>
+
+const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature)
+{
+    static const uint32_t deep_features[] = INIT_DEEP_FEATURES;
+    static const struct {
+        uint32_t feature;
+        uint32_t fs[FEATURESET_NR_ENTRIES];
+    } deep_deps[] = INIT_DEEP_DEPS;
+    unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
+
+    BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
+
+    /* Fast early exit. */
+    if ( !test_bit(feature, deep_features) )
+        return NULL;
+
+    /* deep_deps[] is sorted.  Perform a binary search. */
+    while ( start < end )
+    {
+        unsigned int mid = start + ((end - start) / 2);
+
+        if ( deep_deps[mid].feature > feature )
+            end = mid;
+        else if ( deep_deps[mid].feature < feature )
+            start = mid + 1;
+        else
+            return deep_deps[mid].fs;
+    }
+
+    return NULL;
+}
+
+/*
+ * 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
new file mode 100644
index 0000000000..8a7cf57f87
--- /dev/null
+++ b/xen/lib/x86/private.h
@@ -0,0 +1,38 @@
+#ifndef XEN_LIB_X86_PRIVATE_H
+#define XEN_LIB_X86_PRIVATE_H
+
+#ifdef __XEN__
+
+#include <xen/bitops.h>
+#include <xen/kernel.h>
+#include <xen/lib.h>
+#include <xen/types.h>
+
+#else
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#include <xen-tools/libs.h>
+
+static inline bool test_bit(unsigned int bit, const void *vaddr)
+{
+    const char *addr = vaddr;
+
+    return addr[bit / 8] & (1u << (bit % 8));
+}
+
+#endif /* __XEN__ */
+
+#endif /* XEN_LIB_X86_PRIVATE_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--
generated by git-patchbot for /home/xen/git/xen.git#staging


_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog