x86, hvm: Add a per-domain parameter to specify shadow or hap.
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 29 Jan 2008 13:46:16 +0000 (13:46 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 29 Jan 2008 13:46:16 +0000 (13:46 +0000)
Signed-off-by: Xu Dongxiao <dongxiao.xu@intel.com>
16 files changed:
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/XendConfig.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py
tools/python/xen/xm/xenapi_create.py
xen/arch/ia64/xen/domain.c
xen/arch/powerpc/domain.c
xen/arch/x86/domain.c
xen/arch/x86/mm/p2m.c
xen/arch/x86/mm/paging.c
xen/common/domain.c
xen/common/domctl.c
xen/include/asm-x86/hvm/domain.h
xen/include/public/domctl.h
xen/include/xen/domain.h
xen/include/xen/sched.h

index 29a1bc0fd24210fc5566518f825c21f40020cc7a..f766d28e7702c90a273360f7dc7280759d01a025 100644 (file)
@@ -97,18 +97,17 @@ static PyObject *pyxc_domain_create(XcObject *self,
                                     PyObject *kwds)
 {
     uint32_t dom = 0, ssidref = 0, flags = 0, target = 0;
-    int      ret, i, hvm = 0;
+    int      ret, i;
     PyObject *pyhandle = NULL;
     xen_domain_handle_t handle = { 
         0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef,
         0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef };
 
-    static char *kwd_list[] = { "domid", "ssidref", "handle", "hvm", "target", NULL };
+    static char *kwd_list[] = { "domid", "ssidref", "handle", "flags", "target", NULL };
 
     if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|iiOii", kwd_list,
-                                     &dom, &ssidref, &pyhandle, &hvm, &target))
+                                     &dom, &ssidref, &pyhandle, &flags, &target))
         return NULL;
-
     if ( pyhandle != NULL )
     {
         if ( !PyList_Check(pyhandle) || 
@@ -124,9 +123,6 @@ static PyObject *pyxc_domain_create(XcObject *self,
         }
     }
 
-    if ( hvm )
-        flags |= XEN_DOMCTL_CDF_hvm_guest;
-
     if ( (ret = xc_domain_create(self->xc_handle, ssidref,
                                  handle, flags, &dom)) < 0 )
         return pyxc_error_to_exception();
index 67803517ebaaee69e98bbe73523ab6333b4a9eae..f543e93f264e24bb37460356da4c27d22ad7da3b 100644 (file)
@@ -130,7 +130,7 @@ XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'display',
                         'soundhw','stdvga', 'usb', 'usbdevice', 'vnc',
                         'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
                         'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
-                        'guest_os_type' ]
+                        'guest_os_type', 'hap']
 
 # Xen API console 'other_config' keys.
 XENAPI_CONSOLE_OTHER_CFG = ['vncunused', 'vncdisplay', 'vnclisten',
@@ -1593,3 +1593,6 @@ class XendConfig(dict):
     def image_type(self):
         stored_type = self['platform'].get('image_type')
         return stored_type or (self.is_hvm() and 'hvm' or 'linux')
+
+    def is_hap(self):
+        return self['platform']['hap']
index 7d0c43fc485988da6bc8bb8dd015dc83ae4c5993..0f866f02a62f6e9542364fe054056e5b9df32d25 100644 (file)
@@ -1626,11 +1626,18 @@ class XendDomainInfo:
         @raise: VmError on error
         """
 
+        hvm_bit_offset = 0
+
+        hap_bit_offset = 1
+
         log.debug('XendDomainInfo.constructDomain')
 
         self.shutdownStartTime = None
 
         hvm = self.info.is_hvm()
+
+        hap = self.info.is_hap()
+
         if hvm:
             info = xc.xeninfo()
             if 'hvm' not in info['xen_caps']:
@@ -1656,7 +1663,7 @@ class XendDomainInfo:
                 domid = 0,
                 ssidref = ssidref,
                 handle = uuid.fromString(self.info['uuid']),
-                hvm = int(hvm),
+                flags = int((hvm << hvm_bit_offset) | (hap << hap_bit_offset)),
                 target = self.info.target())
         except Exception, e:
             # may get here if due to ACM the operation is not permitted
index b201c548db6b17c75eb28efba0a971c11b03d49a..417589b07cd9fa3cf2a1c80172c650d3b093c29a 100644 (file)
@@ -525,6 +525,11 @@ gopts.var('target', val='TARGET',
           fn=set_int, default=0,
           use="Set domain target.")
 
+gopts.var('hap', val='HAP',
+          fn=set_int, default=1,
+          use="""Hap status (0=hap is disabled;
+          1=hap is enabled.""")
+
 def err(msg):
     """Print an error to stderr and exit.
     """
@@ -728,7 +733,7 @@ def configure_hvm(config_image, vals):
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
              'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci',
-             'guest_os_type']
+             'guest_os_type', 'hap']
 
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:
index 29ef6efb70876b9101cbbb5a30de297a1459356f..04abcc4e4e80235f5e7c7bd95c30fd626aabaf06 100644 (file)
@@ -818,7 +818,7 @@ class sxp2xml:
 
 
     def extract_platform(self, image, document):
-        platform_keys = ['acpi', 'apic', 'pae', 'vhpt', 'timer_mode']
+        platform_keys = ['acpi', 'apic', 'pae', 'vhpt', 'timer_mode', 'hap']
 
         def extract_platform_key(key):
             platform = document.createElement("platform")
index 3ba5b996cc143ced866496b49c0b470aa601104b..0e54987a3436c013e38f99d32a39ae89335a5bf2 100644 (file)
@@ -559,7 +559,7 @@ static int opt_pervcpu_vhpt = 1;
 integer_param("pervcpu_vhpt", opt_pervcpu_vhpt);
 #endif
 
-int arch_domain_create(struct domain *d)
+int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 {
        int i;
        struct page_info *page = NULL;
index 214a257385025115abe058833224899112194628..3be2fdbe8421c7dda4d8817d83e740e645b0d775 100644 (file)
@@ -76,7 +76,7 @@ unsigned long hypercall_create_continuation(unsigned int op,
     return XEN_MARK(op);
 }
 
-int arch_domain_create(struct domain *d)
+int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 {
     if (d->domain_id == IDLE_DOMAIN_ID) {
         d->shared_info = (void *)alloc_xenheap_page();
index 618542f20fb180620227a1f29a3e5d4b6160e9ac..9d0537a9f99433f01229c3d638310cc94fc198f1 100644 (file)
@@ -435,7 +435,7 @@ void vcpu_destroy(struct vcpu *v)
         hvm_vcpu_destroy(v);
 }
 
-int arch_domain_create(struct domain *d)
+int arch_domain_create(struct domain *d, unsigned int domcr_flags)
 {
 #ifdef __x86_64__
     struct page_info *pg;
@@ -445,6 +445,11 @@ int arch_domain_create(struct domain *d)
     int vcpuid, pdpt_order, paging_initialised = 0;
     int rc = -ENOMEM;
 
+    d->arch.hvm_domain.hap_enabled =
+        is_hvm_domain(d) &&
+        hvm_funcs.hap_supported &&
+        (domcr_flags & DOMCRF_hap);
+
     d->arch.relmem = RELMEM_not_started;
     INIT_LIST_HEAD(&d->arch.relmem_list);
 
index cb3e6a066de3ac7d54e6222834673daba3986290..ee98ae8c6ab6e628e800324ca1f3cc70096dcd58 100644 (file)
@@ -710,7 +710,8 @@ guest_physmap_add_entry(struct domain *d, unsigned long gfn,
     {
         if ( !test_and_set_bool(d->arch.hvm_domain.amd_npt_4gb_warning) )
             dprintk(XENLOG_WARNING, "Dom%d failed to populate memory beyond"
-                    " 4GB: remove 'hap' Xen boot parameter.\n",
+                    " 4GB: specify 'nohap' Xen boot parameter, or 'hap=0' "
+                    "domain config option.\n",
                     d->domain_id);
         return -EINVAL;
     }
index cf5d54e2101fa3c489948d5d38e01fab40654711..c22818e75568eed655fc079eca47113804866bc4 100644 (file)
@@ -28,7 +28,7 @@
 #include <asm/guest_access.h>
 #include <xsm/xsm.h>
 
-#define hap_enabled(d) (hvm_funcs.hap_supported && is_hvm_domain(d))
+#define hap_enabled(d) (is_hvm_domain(d) && (d)->arch.hvm_domain.hap_enabled)
 
 /* Printouts */
 #define PAGING_PRINTK(_f, _a...)                                     \
index a888d88d796a785c733079d4fdb4e9a42824251a..112978f82c65abdecfa388c9dd2fc02f85a2aa32 100644 (file)
@@ -217,7 +217,7 @@ struct domain *domain_create(
         init_status |= INIT_gnttab;
     }
 
-    if ( arch_domain_create(d) != 0 )
+    if ( arch_domain_create(d, domcr_flags) != 0 )
         goto fail;
     init_status |= INIT_arch;
 
index 83d191d93ac5b9c04c795f2f1c54a7e01555ee58..2660af36d8d9a3e0895d5730d112afc6497e667d 100644 (file)
@@ -338,7 +338,8 @@ resumedomain_out:
 
         ret = -EINVAL;
         if ( supervisor_mode_kernel ||
-             (op->u.createdomain.flags & ~XEN_DOMCTL_CDF_hvm_guest) )
+             (op->u.createdomain.flags &
+             ~(XEN_DOMCTL_CDF_hvm_guest | XEN_DOMCTL_CDF_hap)) )
             break;
 
         dom = op->domain;
@@ -368,6 +369,8 @@ resumedomain_out:
         domcr_flags = 0;
         if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hvm_guest )
             domcr_flags |= DOMCRF_hvm;
+        if ( op->u.createdomain.flags & XEN_DOMCTL_CDF_hap )
+            domcr_flags |= DOMCRF_hap;
 
         ret = -ENOMEM;
         d = domain_create(dom, domcr_flags, op->u.createdomain.ssidref);
index 5a17c2507622d92f55520055cb3fdf674f573b9c..0e6ee2ace483827cc757872515d236526841a41e 100644 (file)
@@ -77,7 +77,7 @@ struct hvm_domain {
 #if CONFIG_PAGING_LEVELS == 3
     bool_t                 amd_npt_4gb_warning;
 #endif
-
+    bool_t                 hap_enabled;
     bool_t                 qemu_mapcache_invalidate;
 };
 
index 99822e3d4618eec1b7d532fdb25d69ccb65d25f3..e40d34af1ae26e5ef173eda04baa4a105057dea8 100644 (file)
@@ -53,6 +53,9 @@ struct xen_domctl_createdomain {
  /* Is this an HVM guest (as opposed to a PV guest)? */
 #define _XEN_DOMCTL_CDF_hvm_guest 0
 #define XEN_DOMCTL_CDF_hvm_guest  (1U<<_XEN_DOMCTL_CDF_hvm_guest)
+ /* Use hardware-assisted paging if available? */
+#define _XEN_DOMCTL_CDF_hap       1
+#define XEN_DOMCTL_CDF_hap        (1U<<_XEN_DOMCTL_CDF_hap)
     uint32_t flags;
 };
 typedef struct xen_domctl_createdomain xen_domctl_createdomain_t;
index 2b3a24cb2dec48b8685c1d8fe42f455ee2faee70..ff471ab930f20b549ac0df8953b01170de4d581a 100644 (file)
@@ -40,7 +40,7 @@ void free_vcpu_struct(struct vcpu *v);
 int  vcpu_initialise(struct vcpu *v);
 void vcpu_destroy(struct vcpu *v);
 
-int arch_domain_create(struct domain *d);
+int arch_domain_create(struct domain *d, unsigned int domcr_flags);
 
 void arch_domain_destroy(struct domain *d);
 
index 83ea5a99c56f3ef9bdb32eb431cf9388a3825709..dc79463ba759d03ab750ea1525b8761ef5a99b51 100644 (file)
@@ -311,6 +311,8 @@ struct domain *domain_create(
  /* DOMCRF_hvm: Create an HVM domain, as opposed to a PV domain. */
 #define _DOMCRF_hvm 0
 #define DOMCRF_hvm  (1U<<_DOMCRF_hvm)
+#define _DOMCRF_hap 1
+#define DOMCRF_hap  (1U<<_DOMCRF_hap)
 
 int construct_dom0(
     struct domain *d,