Skip to contentSkip to conversation

sysctl/libxl: choose a sane default for HAP

PATCH In review Roger Pau Monne 5 participants 8 messages Sep 10, 2019 – Sep 12, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/2 sysctl/libxl: choose a sane default for HAP

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')

---
Cc: Paul Durrant <[email protected]>
---
Changes since v3:
- Add ocaml flags.

Changes since v2:
- Add a LIBXL_HAVE_PHYSINFO_CAP_HAP for compatibility.

Changes since v1:
- Also report HAP capability for ARM.
- Print hap capability in xl info.

---
 tools/libxl/libxl.c             | 1 +
 tools/libxl/libxl.h             | 7 +++++++
 tools/libxl/libxl_create.c      | 8 +++++++-
 tools/libxl/libxl_types.idl     | 1 +
 tools/ocaml/libs/xc/xenctrl.ml  | 1 +
 tools/ocaml/libs/xc/xenctrl.mli | 1 +
 tools/xl/xl_info.c              | 5 +++--
 xen/arch/arm/sysctl.c           | 2 +-
 xen/arch/x86/sysctl.c           | 2 ++
 xen/include/public/sysctl.h     | 5 ++++-
 10 files changed, 28 insertions(+), 5 deletions(-)
tools/libxl/libxl.c +1 -0
index ec71574e99..5c0fcf320e 100644
@@ -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;
tools/libxl/libxl.h +7 -0
index 9bacfb97f0..3ff67792a7 100644
@@ -394,6 +394,13 @@
  */
 #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
  *
tools/libxl/libxl_create.c +7 -1
index 79e010da72..3b45065597 100644
@@ -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);
     }
 
tools/libxl/libxl_types.idl +1 -0
index b61399ce36..9e1f8515d3 100644
@@ -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", [
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index e544ef84da..a5e77c943a 100644
@@ -107,6 +107,7 @@ type physinfo_cap_flag =
 	| CAP_HVM
 	| CAP_PV
 	| CAP_DirectIO
+	| CAP_hap
 
 type physinfo =
 {
tools/ocaml/libs/xc/xenctrl.mli +1 -0
index 5a35000761..e92256654b 100644
@@ -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;
tools/xl/xl_info.c +3 -2
index 46d9c9f712..aa6724bc7f 100644
@@ -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);
xen/arch/arm/sysctl.c +1 -1
index 92ac99c928..f87944e847 100644
@@ -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,
xen/arch/x86/sysctl.c +2 -0
index 7ec6174e6b..5777a05ffc 100644
@@ -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(
xen/include/public/sysctl.h +4 -1
index 5401f9c2fe..d4b455619c 100644
@@ -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;
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v4 2/2 sysctl: report shadow paging capability

Report whether shadow paging is supported by the hypervisor, since it can be disabled at build time.

---
NB: I'm not sure the added check in libxl__domain_create_info_setdefault is that useful, or if it could be better placed somewhere else.
---
Changes since v3:
- New in this version.

---
 tools/libxl/libxl.c             | 2 ++
 tools/libxl/libxl.h             | 6 ++++++
 tools/libxl/libxl_create.c      | 5 +++++
 tools/libxl/libxl_types.idl     | 1 +
 tools/ocaml/libs/xc/xenctrl.ml  | 1 +
 tools/ocaml/libs/xc/xenctrl.mli | 1 +
 tools/xl/xl_info.c              | 5 +++--
 xen/arch/x86/sysctl.c           | 2 ++
 xen/include/public/sysctl.h     | 5 ++++-
 9 files changed, 25 insertions(+), 3 deletions(-)
tools/libxl/libxl.c +2 -0
index 5c0fcf320e..57073c06d5 100644
@@ -400,6 +400,8 @@ int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo)
     physinfo->cap_hvm_directio =
         !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_directio);
     physinfo->cap_hap = !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_hap);
+    physinfo->cap_shadow =
+        !!(xcphysinfo.capabilities & XEN_SYSCTL_PHYSCAP_shadow);
 
     GC_FREE;
     return 0;
tools/libxl/libxl.h +6 -0
index 3ff67792a7..e8f5ebe929 100644
@@ -401,6 +401,12 @@
  */
 #define LIBXL_HAVE_PHYSINFO_CAP_HAP 1
 
+/*
+ * LIBXL_HAVE_PHYSINFO_CAP_HAP indicates that libxl_physinfo has a cap_shadow
+ * field that indicates whether software implemented paging is supported.
+ */
+#define LIBXL_HAVE_PHYSINFO_CAP_SHADOW 1
+
 /*
  * libxl ABI compatibility
  *
tools/libxl/libxl_create.c +5 -0
index 3b45065597..47f10da465 100644
@@ -44,6 +44,11 @@ int libxl__domain_create_info_setdefault(libxl__gc *gc,
         if (rc)
             return rc;
 
+        if (!info.cap_hap && !info.cap_shadow) {
+            LOG(ERROR, "neither hap nor shadow paging available");
+            return ERROR_INVAL;
+        }
+
         libxl_defbool_setdefault(&c_info->hap, info.cap_hap);
         libxl_defbool_setdefault(&c_info->oos, true);
     }
tools/libxl/libxl_types.idl +1 -0
index 9e1f8515d3..6f431baec2 100644
@@ -1026,6 +1026,7 @@ libxl_physinfo = Struct("physinfo", [
     ("cap_pv", bool),
     ("cap_hvm_directio", bool), # No longer HVM specific
     ("cap_hap", bool),
+    ("cap_shadow", bool),
     ], dir=DIR_OUT)
 
 libxl_connectorinfo = Struct("connectorinfo", [
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index a5e77c943a..9f56e1df1a 100644
@@ -108,6 +108,7 @@ type physinfo_cap_flag =
 	| CAP_PV
 	| CAP_DirectIO
 	| CAP_hap
+	| CAP_shadow
 
 type physinfo =
 {
tools/ocaml/libs/xc/xenctrl.mli +1 -0
index e92256654b..e06c53d0fa 100644
@@ -93,6 +93,7 @@ type physinfo_cap_flag =
   | CAP_PV
   | CAP_DirectIO
   | CAP_hap
+  | CAP_shadow
 type physinfo = {
   threads_per_core : int;
   cores_per_socket : int;
tools/xl/xl_info.c +3 -2
index aa6724bc7f..148c4740ae 100644
@@ -210,12 +210,13 @@ 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%s\n",
+    maybe_printf("virt_caps              :%s%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_hap ? " hap" : ""
+         info.cap_hap ? " hap" : "",
+         info.cap_shadow ? " shadow" : ""
         );
 
     vinfo = libxl_get_version_info(ctx);
xen/arch/x86/sysctl.c +2 -0
index 5777a05ffc..50be0c722a 100644
@@ -165,6 +165,8 @@ void arch_do_physinfo(struct xen_sysctl_physinfo *pi)
         pi->capabilities |= XEN_SYSCTL_PHYSCAP_pv;
     if ( hvm_hap_supported() )
         pi->capabilities |= XEN_SYSCTL_PHYSCAP_hap;
+    if ( IS_ENABLED(CONFIG_SHADOW_PAGING) )
+        pi->capabilities |= XEN_SYSCTL_PHYSCAP_shadow;
 }
 
 long arch_do_sysctl(
xen/include/public/sysctl.h +4 -1
index d4b455619c..e324442f92 100644
@@ -93,9 +93,12 @@ struct xen_sysctl_tbuf_op {
 /* The platform supports Hardware Assisted Paging. */
 #define _XEN_SYSCTL_PHYSCAP_hap          3
 #define XEN_SYSCTL_PHYSCAP_hap           (1u<<_XEN_SYSCTL_PHYSCAP_hap)
+/* The platform supports software paging. */
+#define _XEN_SYSCTL_PHYSCAP_shadow       4
+#define XEN_SYSCTL_PHYSCAP_shadow        (1u<<_XEN_SYSCTL_PHYSCAP_shadow)
 
 /* Max XEN_SYSCTL_PHYSCAP_* constant.  Used for ABI checking. */
-#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_hap
+#define XEN_SYSCTL_PHYSCAP_MAX XEN_SYSCTL_PHYSCAP_shadow
 
 struct xen_sysctl_physinfo {
     uint32_t threads_per_core;
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v4 2/2
#2 lore raw

Re: [Xen-devel] [PATCH v4 2/2] sysctl: report shadow paging capability

Quoted 5 lines · Roger Pau Monne

Report whether shadow paging is supported by the hypervisor, since it can be disabled at build time.

The straightforward hypervisor part

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [Xen-devel] [PATCH v4 2/2] sysctl: report shadow paging capability

In reply to Roger Pau Monne
Quoted 5 lines · Roger Pau Monne
tools/libxl/libxl.h +0 -0
index 3ff67792a7..e8f5ebe929 100644

tools/libxl/libxl.h line 409

Quoted 9 lines
tools/libxl/libxl.h +6 -0
@@ -401,6 +401,12 @@
  */
 #define LIBXL_HAVE_PHYSINFO_CAP_HAP 1
 
+/*
+ * LIBXL_HAVE_PHYSINFO_CAP_HAP indicates that libxl_physinfo has a cap_shadow
+ * field that indicates whether software implemented paging is supported.
+ */
+#define LIBXL_HAVE_PHYSINFO_CAP_SHADOW 1
+

Is it really worth doing this, and not extending the previous define? Very little point having two going into the tree at the same time.

tools/ocaml/libs/xc/xenctrl.ml type physinfo_cap_flag = · line 111

Quoted 9 lines
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index a5e77c943a..9f56e1df1a 100644
@@ -108,6 +108,7 @@ type physinfo_cap_flag =
 	| CAP_PV
 	| CAP_DirectIO
 	| CAP_hap
+	| CAP_shadow

Similarly as with HAP, this should at least be Shadow to match DirectIO.

Can be fixed on commit.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v4 2/2
#4 lore raw

Re: [Xen-devel] [PATCH v4 2/2] sysctl: report shadow paging capability

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH v4 2/2] sysctl: report shadow paging capability"):

Quoted 2 lines

Report whether shadow paging is supported by the hypervisor, since it can be disabled at build time.

...

Quoted 3 lines

NB: I'm not sure the added check in libxl__domain_create_info_setdefault is that useful, or if it could be better placed somewhere else.

tools/libxl/libxl_create.c int libxl__domain_create_info_setdefault(libxl__gc *gc, · line 52

Quoted 6 lines
tools/libxl/libxl_create.c +5 -0
+        if (!info.cap_hap && !info.cap_shadow) {
+            LOG(ERROR, "neither hap nor shadow paging available");
+            return ERROR_INVAL;
+        }
+
         libxl_defbool_setdefault(&c_info->hap, info.cap_hap);

I would have written

  if (cap_hap) setdefault(info->hap, true);
  else if (cap_shadow) setdefault(info->hap, false);
  else bomb_out();

but the result is equivalent.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v4 1/2
#5 lore raw
In reply to Roger Pau Monne
Quoted 21 lines · Roger Pau Monne
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index e544ef84da..a5e77c943a 100644
@@ -107,6 +107,7 @@ type physinfo_cap_flag =
 	| CAP_HVM
 	| CAP_PV
 	| CAP_DirectIO
+	| CAP_hap
 

type physinfo =
{

tools/ocaml/libs/xc/xenctrl.mli +0 -0
index 5a35000761..e92256654b 100644

tools/ocaml/libs/xc/xenctrl.mli type physinfo_cap_flag = · line 95

Quoted 4 lines
tools/ocaml/libs/xc/xenctrl.mli +1 -0
@@ -92,6 +92,7 @@ type physinfo_cap_flag =
  | CAP_HVM
  | CAP_PV
  | CAP_DirectIO
+  | CAP_hap

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
In reply to Roger Pau Monne

tools/ocaml/libs/xc/xenctrl.ml type physinfo_cap_flag = · line 110

Quoted 9 lines · Roger Pau Monne
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index e544ef84da..a5e77c943a 100644
@@ -107,6 +107,7 @@ type physinfo_cap_flag =
 	| CAP_HVM
 	| CAP_PV
 	| CAP_DirectIO
+	| CAP_hap

HAP is an initialism just like HVM, so definitely should be capitalised.

IMO, DirectIO being not all caps is a bug, but its in the API now.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
Quoted 12 lines · Andrew Cooper

tools/ocaml/libs/xc/xenctrl.ml type physinfo_cap_flag = · line 110

Quoted 9 lines · Roger Pau Monne
tools/ocaml/libs/xc/xenctrl.ml +1 -0
index e544ef84da..a5e77c943a 100644
@@ -107,6 +107,7 @@ type physinfo_cap_flag =
 	| CAP_HVM
 	| CAP_PV
 	| CAP_DirectIO
+	| CAP_hap

HAP is an initialism just like HVM, so definitely should be capitalised.

Funny thing, I had it all caps and then switched to this form to match the sysctl define (XEN_SYSCTL_PHYSCAP_hap).

Would you like me to resend with all caps?

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel