]> xenbits.xensource.com Git - xen.git/commitdiff
x86/msr: introduce struct msr_domain_policy
authorSergey Dyasli <sergey.dyasli@citrix.com>
Mon, 25 Sep 2017 08:53:00 +0000 (10:53 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 25 Sep 2017 08:53:00 +0000 (10:53 +0200)
The new structure contains information about guest's MSRs that are
shared between all domain's vCPUs. It starts with only 1 MSR:

    MSR_INTEL_PLATFORM_INFO

Which currently has only 1 usable bit: cpuid_faulting.

Add 2 global policy objects: hvm_max and pv_max that are inited during
boot up. It's always possible to emulate CPUID faulting for HVM guests
while for PV guests the H/W support is required.

Add init_domain_msr_policy() which sets initial MSR policy during
domain creation with a special case for Dom0.

Signed-off-by: Sergey Dyasli <sergey.dyasli@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
xen/arch/x86/Makefile
xen/arch/x86/domain.c
xen/arch/x86/msr.c [new file with mode: 0644]
xen/arch/x86/setup.c
xen/include/asm-x86/domain.h
xen/include/asm-x86/msr.h

index 93ead6e5dd715f79e9e0200395cdd1dfee99366e..d5d58a205ec80f9ff89446eab082f8ce73ae3fce 100644 (file)
@@ -35,6 +35,7 @@ obj-y += i8259.o
 obj-y += io_apic.o
 obj-$(CONFIG_LIVEPATCH) += alternative.o livepatch.o
 obj-y += msi.o
+obj-y += msr.o
 obj-y += ioport_emulate.o
 obj-y += irq.o
 obj-$(CONFIG_KEXEC) += machine_kexec.o
index e9367bd8aaf8488d050b38394135c8de4d180457..ca64903132af66e8bae42425216764ae17a599df 100644 (file)
@@ -432,6 +432,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     {
         d->arch.emulation_flags = 0;
         d->arch.cpuid = ZERO_BLOCK_PTR; /* Catch stray misuses. */
+        d->arch.msr = ZERO_BLOCK_PTR;
     }
     else
     {
@@ -477,6 +478,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         if ( (rc = init_domain_cpuid_policy(d)) )
             goto fail;
 
+        if ( (rc = init_domain_msr_policy(d)) )
+            goto fail;
+
         d->arch.ioport_caps = 
             rangeset_new(d, "I/O Ports", RANGESETF_prettyprint_hex);
         rc = -ENOMEM;
@@ -547,6 +551,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     cleanup_domain_irq_mapping(d);
     free_xenheap_page(d->shared_info);
     xfree(d->arch.cpuid);
+    xfree(d->arch.msr);
     if ( paging_initialised )
         paging_final_teardown(d);
     free_perdomain_mappings(d);
@@ -561,6 +566,7 @@ void arch_domain_destroy(struct domain *d)
 
     xfree(d->arch.e820);
     xfree(d->arch.cpuid);
+    xfree(d->arch.msr);
 
     free_domain_pirqs(d);
     if ( !is_idle_domain(d) )
diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c
new file mode 100644 (file)
index 0000000..eac50ec
--- /dev/null
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * arch/x86/msr.c
+ *
+ * Policy objects for Model-Specific Registers.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (c) 2017 Citrix Systems Ltd.
+ */
+
+#include <xen/init.h>
+#include <xen/lib.h>
+#include <xen/sched.h>
+#include <asm/msr.h>
+
+struct msr_domain_policy __read_mostly hvm_max_msr_domain_policy,
+                         __read_mostly  pv_max_msr_domain_policy;
+
+static void __init calculate_hvm_max_policy(void)
+{
+    struct msr_domain_policy *dp = &hvm_max_msr_domain_policy;
+
+    if ( !hvm_enabled )
+        return;
+
+    /* 0x000000ce  MSR_INTEL_PLATFORM_INFO */
+    if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
+    {
+        dp->plaform_info.available = true;
+        dp->plaform_info.cpuid_faulting = true;
+    }
+}
+
+static void __init calculate_pv_max_policy(void)
+{
+    struct msr_domain_policy *dp = &pv_max_msr_domain_policy;
+
+    /* 0x000000ce  MSR_INTEL_PLATFORM_INFO */
+    if ( cpu_has_cpuid_faulting )
+    {
+        dp->plaform_info.available = true;
+        dp->plaform_info.cpuid_faulting = true;
+    }
+}
+
+void __init init_guest_msr_policy(void)
+{
+    calculate_hvm_max_policy();
+    calculate_pv_max_policy();
+}
+
+int init_domain_msr_policy(struct domain *d)
+{
+    struct msr_domain_policy *dp;
+
+    dp = xmalloc(struct msr_domain_policy);
+
+    if ( !dp )
+        return -ENOMEM;
+
+    *dp = is_pv_domain(d) ? pv_max_msr_domain_policy :
+                            hvm_max_msr_domain_policy;
+
+    /* See comment in intel_ctxt_switch_levelling() */
+    if ( is_control_domain(d) )
+    {
+        dp->plaform_info.available = false;
+        dp->plaform_info.cpuid_faulting = false;
+    }
+
+    d->arch.msr = dp;
+
+    return 0;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 3cbe305202e5682c5b356533fbe7c82597f45624..32bb02e3a5b9ccf1135fbf74bad9c656ddcd2c98 100644 (file)
@@ -1575,6 +1575,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
         panic("Could not protect TXT memory regions");
 
     init_guest_cpuid();
+    init_guest_msr_policy();
 
     if ( dom0_pvh )
     {
index fb8bf17458633b6feaa1fa8f037f43d456df9ed9..1734eb0e257d436f1f065a76c1bcd0712d9c84c2 100644 (file)
@@ -356,8 +356,9 @@ struct arch_domain
      */
     uint8_t x87_fip_width;
 
-    /* CPUID Policy. */
+    /* CPUID and MSR policy objects. */
     struct cpuid_policy *cpuid;
+    struct msr_domain_policy *msr;
 
     struct PITState vpit;
 
index 7004b6f39890c55bb08f7ad7a0330dd983b2560b..5cf7be1821ebf459c62f55ce9bdd06c3b91e3917 100644 (file)
@@ -202,6 +202,19 @@ void write_efer(u64 val);
 
 DECLARE_PER_CPU(u32, ler_msr);
 
+/* MSR policy object for shared per-domain MSRs */
+struct msr_domain_policy
+{
+    /* 0x000000ce  MSR_INTEL_PLATFORM_INFO */
+    struct {
+        bool available; /* This MSR is non-architectural */
+        bool cpuid_faulting;
+    } plaform_info;
+};
+
+void init_guest_msr_policy(void);
+int init_domain_msr_policy(struct domain *d);
+
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_MSR_H */