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

[Xen-devel] [PATCH v3 11/32] xen/x86: add bitmap of enabled emulated devices



Introduce a bitmap in x86 xen_arch_domainconfig that allows enabling or
disabling specific devices emulated inside of Xen for HVM guests.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Jan Beulich <jbeulich@xxxxxxxx>
Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
 tools/libxl/libxl_x86.c           |  6 ++++--
 xen/arch/x86/domain.c             | 15 +++++++++++++++
 xen/include/asm-x86/domain.h      | 13 +++++++++++++
 xen/include/public/arch-x86/xen.h | 20 +++++++++++++++++++-
 4 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index ed2bd38..f04433a 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -5,8 +5,10 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
                                       xc_domain_configuration_t *xc_config)
 {
-    /* No specific configuration right now */
-
+    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM)
+        xc_config->emulation_flags = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER |
+                                      EMU_RTC | EMU_IOAPIC | EMU_PIC |
+                                      EMU_PMU | EMU_VGA | EMU_IOMMU);
     return 0;
 }
 
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index a112953..d684f49 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -528,6 +528,7 @@ int arch_domain_create(struct domain *d, unsigned int 
domcr_flags,
 {
     int i, paging_initialised = 0;
     int rc = -ENOMEM;
+    uint32_t emulation_mask;
 
     d->arch.s3_integrity = !!(domcr_flags & DOMCRF_s3_integrity);
 
@@ -550,6 +551,20 @@ int arch_domain_create(struct domain *d, unsigned int 
domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (EMU_LAPIC | EMU_HPET | EMU_PMTIMER | EMU_RTC |
+                          EMU_IOAPIC | EMU_PIC | EMU_PMU | EMU_VGA | 
EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "Xen does not allow HVM creation with the "
+                   "current selection of emulators: 0x%x.\n",
+                   config->emulation_flags);
+            return -EPERM;
+        }
+        d->arch.emulation_flags = config->emulation_flags;
+    }
+
     if ( has_hvm_container_domain(d) )
     {
         d->arch.hvm_domain.hap_enabled =
diff --git a/xen/include/asm-x86/domain.h b/xen/include/asm-x86/domain.h
index 96bde65..502379e 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -356,8 +356,21 @@ struct arch_domain
 
     /* Mem_access emulation control */
     bool_t mem_access_emulate_enabled;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;
 
+#define has_vlapic(d)       (d->arch.emulation_flags & EMU_LAPIC)
+#define has_vhpet(d)        (d->arch.emulation_flags & EMU_HPET)
+#define has_vpmtimer(d)     (d->arch.emulation_flags & EMU_PMTIMER)
+#define has_vrtc(d)         (d->arch.emulation_flags & EMU_RTC)
+#define has_vioapic(d)      (d->arch.emulation_flags & EMU_IOAPIC)
+#define has_vpic(d)         (d->arch.emulation_flags & EMU_PIC)
+#define has_vpmu(d)         (d->arch.emulation_flags & EMU_PMU)
+#define has_vvga(d)         (d->arch.emulation_flags & EMU_VGA)
+#define has_viommu(d)       (d->arch.emulation_flags & EMU_IOMMU)
+
 #define has_arch_pdevs(d)    (!list_empty(&(d)->arch.pdev_list))
 
 #define gdt_ldt_pt_idx(v) \
diff --git a/xen/include/public/arch-x86/xen.h 
b/xen/include/public/arch-x86/xen.h
index 2ecc9c9..6b387a3 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -268,7 +268,25 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _EMU_LAPIC                  0
+#define EMU_LAPIC                   (1U<<_EMU_LAPIC)
+#define _EMU_HPET                   1
+#define EMU_HPET                    (1U<<_EMU_HPET)
+#define _EMU_PMTIMER                2
+#define EMU_PMTIMER                 (1U<<_EMU_PMTIMER)
+#define _EMU_RTC                    3
+#define EMU_RTC                     (1U<<_EMU_RTC)
+#define _EMU_IOAPIC                 4
+#define EMU_IOAPIC                  (1U<<_EMU_IOAPIC)
+#define _EMU_PIC                    5
+#define EMU_PIC                     (1U<<_EMU_PIC)
+#define _EMU_PMU                    6
+#define EMU_PMU                     (1U<<_EMU_PMU)
+#define _EMU_VGA                    7
+#define EMU_VGA                     (1U<<_EMU_VGA)
+#define _EMU_IOMMU                  8
+#define EMU_IOMMU                   (1U<<_EMU_IOMMU)
+    uint32_t emulation_flags;
 };
 #endif
 
-- 
1.9.5 (Apple Git-50.3)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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