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

[Xen-devel] [PATCH v4 12/31] 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>
---
Changes since v3:
 - Return EOPNOTSUPP instead of ENOPERM if an invalid emulation mask is
   used.
 - Fix error messages (prefix them with d%d and use %#x instead of 0x%x).
 - Clearly state in the public header that emulation_flags should only be
   used with HVM guests.
 - Add a XEN_X86 prefix to the emulation flags defines.
 - Properly parenthese the has_* marcos.
---
 tools/libxl/libxl_x86.c           |  8 ++++++--
 xen/arch/x86/domain.c             | 18 ++++++++++++++++++
 xen/include/asm-x86/domain.h      | 13 +++++++++++++
 xen/include/public/arch-x86/xen.h | 21 ++++++++++++++++++++-
 4 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_x86.c b/tools/libxl/libxl_x86.c
index b887411..270f3cf 100644
--- a/tools/libxl/libxl_x86.c
+++ b/tools/libxl/libxl_x86.c
@@ -7,8 +7,12 @@ 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 = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                                      XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                                      XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                                      XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                                      XEN_X86_EMU_IOMMU);
     return 0;
 }
 
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 045f6ff..c508074 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -533,6 +533,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);
 
@@ -555,6 +556,23 @@ int arch_domain_create(struct domain *d, unsigned int 
domcr_flags,
                d->domain_id);
     }
 
+    if ( is_hvm_domain(d) )
+    {
+        emulation_mask = (XEN_X86_EMU_LAPIC | XEN_X86_EMU_HPET |
+                          XEN_X86_EMU_PMTIMER | XEN_X86_EMU_RTC |
+                          XEN_X86_EMU_IOAPIC | XEN_X86_EMU_PIC |
+                          XEN_X86_EMU_PMU | XEN_X86_EMU_VGA |
+                          XEN_X86_EMU_IOMMU);
+        if ( (config->emulation_flags & emulation_mask) != emulation_mask )
+        {
+            printk(XENLOG_G_ERR "d%d: Xen does not allow HVM creation with the 
"
+                   "current selection of emulators: %#x.\n", d->domain_id,
+                   config->emulation_flags);
+            return -EOPNOTSUPP;
+        }
+        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 0fce09e..2527637 100644
--- a/xen/include/asm-x86/domain.h
+++ b/xen/include/asm-x86/domain.h
@@ -387,8 +387,21 @@ struct arch_domain
     bool_t mem_access_emulate_enabled;
 
     struct monitor_write_data *event_write_data;
+
+    /* Emulated devices enabled bitmap. */
+    uint32_t emulation_flags;
 } __cacheline_aligned;
 
+#define has_vlapic(d)       ((d)->arch.emulation_flags & XEN_X86_EMU_LAPIC)
+#define has_vhpet(d)        ((d)->arch.emulation_flags & XEN_X86_EMU_HPET)
+#define has_vpmtimer(d)     ((d)->arch.emulation_flags & XEN_X86_EMU_PMTIMER)
+#define has_vrtc(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_RTC)
+#define has_vioapic(d)      ((d)->arch.emulation_flags & XEN_X86_EMU_IOAPIC)
+#define has_vpic(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PIC)
+#define has_vpmu(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_PMU)
+#define has_vvga(d)         ((d)->arch.emulation_flags & XEN_X86_EMU_VGA)
+#define has_viommu(d)       ((d)->arch.emulation_flags & XEN_X86_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..98cae41 100644
--- a/xen/include/public/arch-x86/xen.h
+++ b/xen/include/public/arch-x86/xen.h
@@ -268,7 +268,26 @@ typedef struct arch_shared_info arch_shared_info_t;
  * XEN_DOMCTL_INTERFACE_VERSION.
  */
 struct xen_arch_domainconfig {
-    char dummy;
+#define _XEN_X86_EMU_LAPIC              0
+#define XEN_X86_EMU_LAPIC               (1U<<_XEN_X86_EMU_LAPIC)
+#define _XEN_X86_EMU_HPET               1
+#define XEN_X86_EMU_HPET                (1U<<_XEN_X86_EMU_HPET)
+#define _XEN_X86_EMU_PMTIMER            2
+#define XEN_X86_EMU_PMTIMER             (1U<<_XEN_X86_EMU_PMTIMER)
+#define _XEN_X86_EMU_RTC                3
+#define XEN_X86_EMU_RTC                 (1U<<_XEN_X86_EMU_RTC)
+#define _XEN_X86_EMU_IOAPIC             4
+#define XEN_X86_EMU_IOAPIC              (1U<<_XEN_X86_EMU_IOAPIC)
+#define _XEN_X86_EMU_PIC                5
+#define XEN_X86_EMU_PIC                 (1U<<_XEN_X86_EMU_PIC)
+#define _XEN_X86_EMU_PMU                6
+#define XEN_X86_EMU_PMU                 (1U<<_XEN_X86_EMU_PMU)
+#define _XEN_X86_EMU_VGA                7
+#define XEN_X86_EMU_VGA                 (1U<<_XEN_X86_EMU_VGA)
+#define _XEN_X86_EMU_IOMMU              8
+#define XEN_X86_EMU_IOMMU               (1U<<_XEN_X86_EMU_IOMMU)
+    /* For HVM guests only, this field is ignored for PV guests. */
+    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®.