[06/10] x86/msr: Introduce and use default MSR policies
diff mbox series

Message ID 20200226202221.6555-7-andrew.cooper3@citrix.com
State New
Headers show
Series
  • x86: Default vs Max policies
Related show

Commit Message

Andrew Cooper Feb. 26, 2020, 8:22 p.m. UTC
For now, the default and max policies remain identical, but this will change
in the future.

Update XEN_SYSCTL_get_cpu_policy and init_domain_msr_policy() to use the
default policies.

Take the opportunity sort PV ahead of HVM, as is the prevailing style
elsewhere.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/arch/x86/msr.c        | 32 +++++++++++++++++++++++++++-----
 xen/arch/x86/sysctl.c     |  4 ++--
 xen/include/asm-x86/msr.h |  4 +++-
 3 files changed, 32 insertions(+), 8 deletions(-)

Comments

Jan Beulich Feb. 27, 2020, 8:11 a.m. UTC | #1
On 26.02.2020 21:22, Andrew Cooper wrote:
> For now, the default and max policies remain identical, but this will change
> in the future.
> 
> Update XEN_SYSCTL_get_cpu_policy and init_domain_msr_policy() to use the
> default policies.
> 
> Take the opportunity sort PV ahead of HVM, as is the prevailing style
> elsewhere.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

Patch
diff mbox series

diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
index 738d7123f9..519222a2b8 100644
--- a/xen/arch/x86/msr.c
+++ b/xen/arch/x86/msr.c
@@ -34,9 +34,11 @@  struct msr_policy __read_mostly     raw_msr_policy,
                   __read_mostly    host_msr_policy;
 #ifdef CONFIG_PV
 struct msr_policy __read_mostly  pv_max_msr_policy;
+struct msr_policy __read_mostly  pv_def_msr_policy;
 #endif
 #ifdef CONFIG_HVM
 struct msr_policy __read_mostly hvm_max_msr_policy;
+struct msr_policy __read_mostly hvm_def_msr_policy;
 #endif
 
 static void __init calculate_raw_policy(void)
@@ -56,6 +58,20 @@  static void __init calculate_host_policy(void)
     mp->platform_info.cpuid_faulting = cpu_has_cpuid_faulting;
 }
 
+static void __init calculate_pv_max_policy(void)
+{
+    struct msr_policy *mp = &pv_max_msr_policy;
+
+    *mp = host_msr_policy;
+}
+
+static void __init calculate_pv_def_policy(void)
+{
+    struct msr_policy *mp = &pv_def_msr_policy;
+
+    *mp = pv_max_msr_policy;
+}
+
 static void __init calculate_hvm_max_policy(void)
 {
     struct msr_policy *mp = &hvm_max_msr_policy;
@@ -66,11 +82,11 @@  static void __init calculate_hvm_max_policy(void)
     mp->platform_info.cpuid_faulting = true;
 }
 
-static void __init calculate_pv_max_policy(void)
+static void __init calculate_hvm_def_policy(void)
 {
-    struct msr_policy *mp = &pv_max_msr_policy;
+    struct msr_policy *mp = &hvm_def_msr_policy;
 
-    *mp = host_msr_policy;
+    *mp = hvm_max_msr_policy;
 }
 
 void __init init_guest_msr_policy(void)
@@ -79,17 +95,23 @@  void __init init_guest_msr_policy(void)
     calculate_host_policy();
 
     if ( IS_ENABLED(CONFIG_PV) )
+    {
         calculate_pv_max_policy();
+        calculate_pv_def_policy();
+    }
 
     if ( hvm_enabled )
+    {
         calculate_hvm_max_policy();
+        calculate_hvm_def_policy();
+    }
 }
 
 int init_domain_msr_policy(struct domain *d)
 {
     struct msr_policy *mp = is_pv_domain(d)
-        ? (IS_ENABLED(CONFIG_PV)  ?  &pv_max_msr_policy : NULL)
-        : (IS_ENABLED(CONFIG_HVM) ? &hvm_max_msr_policy : NULL);
+        ? (IS_ENABLED(CONFIG_PV)  ?  &pv_def_msr_policy : NULL)
+        : (IS_ENABLED(CONFIG_HVM) ? &hvm_def_msr_policy : NULL);
 
     if ( !mp )
     {
diff --git a/xen/arch/x86/sysctl.c b/xen/arch/x86/sysctl.c
index 7ea8c38797..cad7534373 100644
--- a/xen/arch/x86/sysctl.c
+++ b/xen/arch/x86/sysctl.c
@@ -49,7 +49,7 @@  const struct cpu_policy system_policies[6] = {
     },
     [ XEN_SYSCTL_cpu_policy_pv_default ] = {
         &pv_max_cpuid_policy,
-        &pv_max_msr_policy,
+        &pv_def_msr_policy,
     },
 #endif
 #ifdef CONFIG_HVM
@@ -59,7 +59,7 @@  const struct cpu_policy system_policies[6] = {
     },
     [ XEN_SYSCTL_cpu_policy_hvm_default ] = {
         &hvm_max_cpuid_policy,
-        &hvm_max_msr_policy,
+        &hvm_def_msr_policy,
     },
 #endif
 };
diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h
index bca41a3670..41397e19cf 100644
--- a/xen/include/asm-x86/msr.h
+++ b/xen/include/asm-x86/msr.h
@@ -269,8 +269,10 @@  static inline void wrmsr_tsc_aux(uint32_t val)
 
 extern struct msr_policy     raw_msr_policy,
                             host_msr_policy,
+                          pv_max_msr_policy,
+                          pv_def_msr_policy,
                          hvm_max_msr_policy,
-                          pv_max_msr_policy;
+                         hvm_def_msr_policy;
 
 /* Container object for per-vCPU MSRs */
 struct vcpu_msrs