x86: Introduce struct cpu_policy to refer to a group of individual policies
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 2 Jul 2018 16:05:33 +0000 (16:05 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 6 Nov 2018 17:51:18 +0000 (17:51 +0000)
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@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/sysctl.c
xen/include/asm-x86/cpuid.h
xen/include/public/sysctl.h
xen/include/xen/lib/x86/cpu-policy.h [new file with mode: 0644]

index 456dc58d8f679d57c6acea317f081bad95e30262..ecb51f999edd22b992cbc14178330e6e178235d5 100644 (file)
 #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;
index f109c6ffb4fa313c8bf067adeb66031251ea9de1..548108f94843a073ebd5e20973f41704e23e5868 100644 (file)
@@ -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);
 
index 8cd0a9cb0dcf9b76cf72571b5b2b731bbf172ea9..9070007222c098a240c9f5302dbe19e09d9f1a53 100644 (file)
@@ -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 (file)
index 0000000..6f07c4b
--- /dev/null
@@ -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:
+ */