]> xenbits.xensource.com Git - people/liuw/xen.git/commitdiff
sysctl/libxl: choose a sane default for HAP
authorRoger Pau Monné <roger.pau@citrix.com>
Wed, 11 Sep 2019 12:55:20 +0000 (14:55 +0200)
committerJan Beulich <jbeulich@suse.com>
Wed, 11 Sep 2019 12:55:20 +0000 (14:55 +0200)
Current libxl code will always enable Hardware Assisted Paging (HAP),
expecting that the hypervisor will fallback to shadow if HAP is not
available. With the changes to DOMCTL_createdomain that's not the case
any longer, and the hypervisor will raise an error if HAP is not
available instead of silently falling back to shadow.

In order to keep the previous functionality report whether HAP is
available or not in XEN_SYSCTL_physinfo, so that the toolstack can
select a sane default if there's no explicit user selection of whether
HAP should be used.

Note that on ARM hardware HAP capability is always reported since it's
a required feature in order to run Xen.

Fixes: d0c0ba7d3de ('x86/hvm/domain: remove the 'hap_enabled' flag')
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@arm.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Christian Lindig <christian.lindig@citrix.com>
tools/libxl/libxl.c
tools/libxl/libxl.h
tools/libxl/libxl_create.c
tools/libxl/libxl_types.idl
tools/ocaml/libs/xc/xenctrl.ml
tools/ocaml/libs/xc/xenctrl.mli
tools/xl/xl_info.c
xen/arch/arm/sysctl.c
xen/arch/x86/sysctl.c
xen/include/public/sysctl.h

index ec71574e998a4e4f4f27bf4694636206b11113ba..5c0fcf320e23c6d4523c2de66c6ae0c5856e9d3c 100644 (file)
@@ -399,6 +399,7 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     physinfo->cap_pv = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_pv);
     physinfo->cap_hvm_directio =
         !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_directio);
+    physinfo->cap_hap = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap);
 
     GC_FREE;
     return 0;
index 9bacfb97f02b234a2f33dd5fef8f6fa12de874ae..3ff67792a7c401b3a965f4059a983103dcd0a6fb 100644 (file)
  */
 #define LIBXL_HAVE_EXTENDED_VKB 1
 
+/*
+ * LIBXL_HAVE_PHYSINFO_CAP_HAP indicates that libxl_physinfo has a cap_hap
+ * field that indicates whether the hardware supports Hardware Assisted
+ * Paging.
+ */
+#define LIBXL_HAVE_PHYSINFO_CAP_HAP 1
+
 /*
  * libxl ABI compatibility
  *
index 79e010da7202b669b6ac6f606ca61a5f913222b3..3b45065597f15cfac4a1e3a97799ebf2dc014db5 100644 (file)
@@ -38,7 +38,13 @@ int libxl__domain_create_info_setdefault(libxl__gc *gc,
     libxl__arch_domain_create_info_setdefault(gc, c_info);
 
     if (c_info->type != LIBXL_DOMAIN_TYPE_PV) {
-        libxl_defbool_setdefault(&c_info->hap, true);
+        libxl_physinfo info;
+        int rc = libxl_get_physinfo(CTX, &info);
+
+        if (rc)
+            return rc;
+
+        libxl_defbool_setdefault(&c_info->hap, info.cap_hap);
         libxl_defbool_setdefault(&c_info->oos, true);
     }
 
index b61399ce36457b4ea4adf0926714ff3ee73dbf30..9e1f8515d3b3dd88b780ec899a1fd3d6a5cce9cf 100644 (file)
@@ -1025,6 +1025,7 @@ libxl_physinfo = Struct("physinfo", [
     ("cap_hvm", bool),
     ("cap_pv", bool),
     ("cap_hvm_directio", bool), # No longer HVM specific
+    ("cap_hap", bool),
     ], dir=DIR_OUT)
 
 libxl_connectorinfo = Struct("connectorinfo", [
index e544ef84da95208219ec622d0e4e5336a2ad4713..bfb3d8e18166b21dfadcf4ee4416e44d85fcdae1 100644 (file)
@@ -107,6 +107,7 @@ type physinfo_cap_flag =
        | CAP_HVM
        | CAP_PV
        | CAP_DirectIO
+       | CAP_HAP
 
 type physinfo =
 {
index 5a350007617d57e1ad9bbda1f314ae54367e499e..8bc36ec8f6f136268b0dc76989e80698a1f9c32a 100644 (file)
@@ -92,6 +92,7 @@ type physinfo_cap_flag =
   | CAP_HVM
   | CAP_PV
   | CAP_DirectIO
+  | CAP_HAP
 type physinfo = {
   threads_per_core : int;
   cores_per_socket : int;
index 46d9c9f712315ef9c10769d77d16a166c497d84f..aa6724bc7f6b6eedcda5296b6eec686c393fc3ec 100644 (file)
@@ -210,11 +210,12 @@ static void output_physinfo(void)
          info.hw_cap[4], info.hw_cap[5], info.hw_cap[6], info.hw_cap[7]
         );
 
-    maybe_printf("virt_caps              :%s%s%s%s\n",
+    maybe_printf("virt_caps              :%s%s%s%s%s\n",
          info.cap_pv ? " pv" : "",
          info.cap_hvm ? " hvm" : "",
          info.cap_hvm && info.cap_hvm_directio ? " hvm_directio" : "",
-         info.cap_pv && info.cap_hvm_directio ? " pv_directio" : ""
+         info.cap_pv && info.cap_hvm_directio ? " pv_directio" : "",
+         info.cap_hap ? " hap" : ""
         );
 
     vinfo = libxl_get_version_info(ctx);
index 92ac99c928de6205f75c70047d107a42bf5ad616..f87944e8473caccd1b9b8e775aae46df406d1ee9 100644 (file)
@@ -14,7 +14,7 @@
 
 void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
 {
-    pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm;
+    pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm | XEN_SYSCTL_PHYSCAP_hap;
 }
 
 long arch_do_sysctl(struct xen_sysctl *sysctl,
index 7ec6174e6bfff65694f36d4cd49b2d114a9abf0d..5777a05ffcc1eed25503e4e00ee032eb2cc3a1a5 100644 (file)
@@ -163,6 +163,8 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
         pi->capabilities |= XEN_SYSCTL_PHYSCAP_hvm;
     if ( IS_ENABLED(CONFIG_PV) )
         pi->capabilities |= XEN_SYSCTL_PHYSCAP_pv;
+    if ( hvm_hap_supported() )
+        pi->capabilities |= XEN_SYSCTL_PHYSCAP_hap;
 }
 
 long arch_do_sysctl(
index 5401f9c2fea8991f425b73d4d1f32c292d6e1756..d4b455619c761ea9d68db017645f2d7c76e25162 100644 (file)
@@ -90,9 +90,12 @@ struct xen_sysctl_tbuf_op {
  /* The platform supports direct access to I/O devices with IOMMU. */
 #define _XEN_SYSCTL_PHYSCAP_directio     2
 #define XEN_SYSCTL_PHYSCAP_directio  (1u<<_XEN_SYSCTL_PHYSCAP_directio)
+/* The platform supports Hardware Assisted Paging. */
+#define _XEN_SYSCTL_PHYSCAP_hap          3
+#define XEN_SYSCTL_PHYSCAP_hap           (1u<<_XEN_SYSCTL_PHYSCAP_hap)
 
 /* Max XEN_SYSCTL_PHYSCAP_* constant.  Used for ABI checking. */
-#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_directio
+#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_hap
 
 struct xen_sysctl_physinfo {
     uint32_t threads_per_core;