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

[Xen-devel] [PATCH v3 3/5] x86: Introduce struct cpu_policy to refer to a group of individual policies



This is prep work for the following patch - please refer to it as well.

When auditing and manipulating policies, it is necessary to do so with a
complete set of policies, due to the interdependences of the contents.  A
containing structure like this will allow for clearer APIs and code.

As a first user, this structure is convenient for the mapping used by
XEN_SYSCTL_get_cpu_policy (implemented in the next patch), and for auditing
(later when XEN_DOMCTL_set_cpu_policy is implemented).

At this point, the distinction between *_max and *_default is introduced into
the ABI.  For now, *_default is mapped to *_max, but future development work
will result in *_default being a logical subset of *_max.

Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Reviewed-by: Wei Liu <wei.liu2@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Sergey Dyasli <sergey.dyasli@xxxxxxxxxx>

v2:
 * Drop __read_mostly from MSR declarations.  Fixes clang build.
 * s/policy_group/cpu_policy/g s/cpumsr_policy/cpu_policy/g
 * Rebase over the msr_{domain,vcpu}_policy rename
 * Don't include vcpu_msrs in the cpu_policy
---
 xen/arch/x86/sysctl.c                | 27 +++++++++++++++++++++++++++
 xen/include/asm-x86/cpuid.h          |  3 +++
 xen/include/public/sysctl.h          | 20 ++++++++++++++++++++
 xen/include/xen/lib/x86/cpu-policy.h | 24 ++++++++++++++++++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 xen/include/xen/lib/x86/cpu-policy.h

diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index 456dc58..ecb51f9 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -32,6 +32,33 @@
 #include <asm/psr.h>
 #include <asm/cpuid.h>
 
+const struct cpu_policy system_policies[] = {
+    [ XEN_SYSCTL_cpu_policy_raw ] = {
+        &raw_cpuid_policy,
+        &raw_msr_policy,
+    },
+    [ XEN_SYSCTL_cpu_policy_host ] = {
+        &host_cpuid_policy,
+        &host_msr_policy,
+    },
+    [ XEN_SYSCTL_cpu_policy_pv_max ] = {
+        &pv_max_cpuid_policy,
+        &pv_max_msr_policy,
+    },
+    [ XEN_SYSCTL_cpu_policy_hvm_max ] = {
+        &hvm_max_cpuid_policy,
+        &hvm_max_msr_policy,
+    },
+    [ XEN_SYSCTL_cpu_policy_pv_default ] = {
+        &pv_max_cpuid_policy,
+        &pv_max_msr_policy,
+    },
+    [ XEN_SYSCTL_cpu_policy_hvm_default ] = {
+        &hvm_max_cpuid_policy,
+        &hvm_max_msr_policy,
+    },
+};
+
 struct l3_cache_info {
     int ret;
     unsigned long size;
diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h
index f109c6f..548108f 100644
--- a/xen/include/asm-x86/cpuid.h
+++ b/xen/include/asm-x86/cpuid.h
@@ -8,6 +8,7 @@
 #include <xen/types.h>
 #include <xen/kernel.h>
 
+#include <xen/lib/x86/cpu-policy.h>
 #include <xen/lib/x86/cpuid.h>
 
 #include <public/sysctl.h>
@@ -50,6 +51,8 @@ extern struct cpuidmasks cpuidmask_defaults;
 extern struct cpuid_policy raw_cpuid_policy, host_cpuid_policy,
     pv_max_cpuid_policy, hvm_max_cpuid_policy;
 
+extern const struct cpu_policy system_policies[];
+
 /* Check that all previously present features are still available. */
 bool recheck_cpu_features(unsigned int cpu);
 
diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h
index 8cd0a9c..9070007 100644
--- a/xen/include/public/sysctl.h
+++ b/xen/include/public/sysctl.h
@@ -1063,6 +1063,26 @@ struct xen_sysctl_set_parameter {
     uint16_t pad[3];                        /* IN: MUST be zero. */
 };
 
+#if defined(__i386__) || defined(__x86_64__)
+/*
+ * XEN_SYSCTL_get_cpu_policy (x86 specific)
+ *
+ * Return information about CPUID and MSR policies available on this host.
+ *  -       Raw: The real H/W values.
+ *  -      Host: The values Xen is using, (after command line overrides, etc).
+ *  -     Max_*: Maximum set of features a PV or HVM guest can use.  Includes
+ *               experimental features outside of security support.
+ *  - Default_*: Default set of features a PV or HVM guest can use.  This is
+ *               the security supported set.
+ */
+#define XEN_SYSCTL_cpu_policy_raw          0
+#define XEN_SYSCTL_cpu_policy_host         1
+#define XEN_SYSCTL_cpu_policy_pv_max       2
+#define XEN_SYSCTL_cpu_policy_hvm_max      3
+#define XEN_SYSCTL_cpu_policy_pv_default   4
+#define XEN_SYSCTL_cpu_policy_hvm_default  5
+#endif
+
 struct xen_sysctl {
     uint32_t cmd;
 #define XEN_SYSCTL_readconsole                    1
diff --git a/xen/include/xen/lib/x86/cpu-policy.h 
b/xen/include/xen/lib/x86/cpu-policy.h
new file mode 100644
index 0000000..6f07c4b
--- /dev/null
+++ b/xen/include/xen/lib/x86/cpu-policy.h
@@ -0,0 +1,24 @@
+/* Common data structures and functions consumed by hypervisor and toolstack */
+#ifndef XEN_LIB_X86_POLICIES_H
+#define XEN_LIB_X86_POLICIES_H
+
+#include <xen/lib/x86/cpuid.h>
+#include <xen/lib/x86/msr.h>
+
+struct cpu_policy
+{
+    struct cpuid_policy *cpuid;
+    struct msr_policy *msr;
+};
+
+#endif /* !XEN_LIB_X86_POLICIES_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

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