Skip to contentSkip to conversation

libxl memkb & pt defaulting

PATCH Superseded Ian Jackson 3 participants 15 messages Oct 11, 2019 – Oct 15, 2019

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover libxl memkb & pt defaulting

This is v3 of my series to sort out the shadow/iommu memory and pci passthrough situation. It is also available here:
https://xenbits.xen.org/gitweb/?p=people/iwj/xen.git;a=summary
wip.libxl-memkb-ptcfg.v3

Thanks to Andrew Cooper and Julien Grall for comments about the PT mode setting, which I think I have taken into account.

 #a  01 libxl: Offer API versions 0x040700 and 0x040800
 #r  02 xl: Pass libxl_domain_config to freemem(), instead of b_info
 #r  03 libxl: libxl__domain_config_setdefault: New function
 #r  04 libxl: libxl_domain_need_memory: Make it take a domain_config
     05 libxl: Move shadow_memkb and iommu_memkb defaulting into libxl
  a  06 libxl: Remove/deprecate libxl_get_required_*_memory from the API
  a  07 libxl: create: setdefault: Make libxl_physinfo info[1]
  a  08 libxl: create: setdefault: Move physinfo into config_setdefault

+ 09 libxl: Move domain_create_info_setdefault earlier
* 10 libxl/xl: Overhaul passthrough setting logic

# = not actually reposted so as to shrink the patchbomb;
unchanged from previous posting
a = acked; r = reviewed
* = patch changed; m = message changed; + = new patch

 docs/man/xl.cfg.5.pod.in     |   6 ++
 tools/libxl/libxl.h          |  24 ++++++-
 tools/libxl/libxl_arch.h     |   6 ++
 tools/libxl/libxl_arm.c      |  24 +++++++
 tools/libxl/libxl_create.c   | 168 ++++++++++++++++++++++++++++++++-----------
 tools/libxl/libxl_dm.c       |   7 +-
 tools/libxl/libxl_dom.c      |   7 +-
 tools/libxl/libxl_internal.h |  13 +++-
 tools/libxl/libxl_mem.c      |  69 ++++++++++++++----
 tools/libxl/libxl_types.idl  |   7 +-
 tools/libxl/libxl_utils.c    |  15 ----
 tools/libxl/libxl_utils.h    |   2 +-
 tools/libxl/libxl_x86.c      |  41 +++++++++++
 tools/xl/xl_parse.c          |  82 ++-------------------
 tools/xl/xl_vmcontrol.c      |   6 +-
 15 files changed, 321 insertions(+), 156 deletions(-)
Signature · 7 lines
2.11.0


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

PATCH v3 5/10 libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

Defaulting is supposed to be done by libxl. So these calculations should be here in libxl. libxl__domain_config_setdefault has all the necessary information including the values of max_memkb and max_vcpus.

The overall functional effect depends on the caller:

For xl, no change. The code moves from xl to libxl.

For callers who set one or both shadow_memkb and iommu_memkb (whether from libxl_get_required_shadow_memory or otherwise) before calling libxl_domain_need_memory (any version): the new code will leave their setting(s) unchanged.

For callers who do not call libxl_domain_need_memory at all, and who fail to set one of these memory values: now they are both are properly set. The shadow and iommu memory to be properly accounted for as intended.

For callers which call libxl_domain_need_memory and request the current API (4.13) or which track libxl, the default values are also now right and everything works as intended.

For callers which call libxl_domain_need_memory, and request an old pre-4.13 libxl API, and which leave one of these memkb settings unset, we take special measures to preserve the old behaviour.

This means that they don't get the additional iommu memory and are at risk of the domain running out of memory as a result of f89f555827a6 "remove late (on-demand) construction of IOMMU page tables". But this is no worse than the state just after f89f555827a6, which already broke such callers in that way. This is perhaps justifiable because of the API stability warning next to libxl_domain_need_memory.

An alternative would be to drop the special-casing of these callers. That would cause a discrepancy between libxl_domain_need_memory and
libxl_domain_create: the former would not include the iommu memory and the latter would. That seems worse, but it's debateable.

---
v2: Replace _Bool with bool
Fix logic sense in ok_to_default_memkb_in_create

---
 tools/libxl/libxl_create.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |  3 +++
 tools/libxl/libxl_mem.c      |  4 ++++
 tools/xl/xl_parse.c          | 15 ++-------------
 4 files changed, 49 insertions(+), 13 deletions(-)
tools/libxl/libxl_create.c +40 -0
index fd8bb22be9..a1b00a8aef 100644
@@ -250,6 +250,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     switch (b_info->type) {
     case LIBXL_DOMAIN_TYPE_HVM:
         if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT)
+            /* Normally defaulted in libxl__domain_create_info_setdefault */
             b_info->shadow_memkb = 0;
         if (b_info->u.hvm.mmio_hole_memkb == LIBXL_MEMKB_DEFAULT)
             b_info->u.hvm.mmio_hole_memkb = 0;
@@ -395,6 +396,7 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
         if (b_info->video_memkb == LIBXL_MEMKB_DEFAULT)
             b_info->video_memkb = 0;
         if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT)
+            /* Normally defaulted in libxl__domain_create_info_setdefault */
             b_info->shadow_memkb = 0;
         if (b_info->u.pv.slack_memkb == LIBXL_MEMKB_DEFAULT)
             b_info->u.pv.slack_memkb = 0;
@@ -862,6 +864,30 @@ static void domcreate_destruction_cb(libxl__egc *egc,
                                      libxl__domain_destroy_state *dds,
                                      int rc);
 
+static bool ok_to_default_memkb_in_create(libxl__gc *gc)
+{
+    /*
+     * This is a fudge.  We are trying to find whether the caller
+     * calls the old version of libxl_domain_need_memory.  If they do
+     * then, because it only gets the b_info, and because it can't
+     * update the b_info (because it's const), it will base its
+     * calculations on defaulting shadow_memkb and iommu_memkb to 0
+     * In that case we probably shouldn't default them differently
+     * during libxl_domain_create.
+     *
+     * The result is that the behaviour with old callers is the same
+     * as in 4.13: no additional memory is allocated for shadow and
+     * iommu (unless the caller set shadow_memkb, eg from a call to
+     * libxl_get_required_shadow_memory).
+     */
+    return !CTX->libxl_domain_need_memory_0x041200_called ||
+            CTX->libxl_domain_need_memory_called;
+    /*
+     * Treat mixed callers as new callers.  Presumably they know what
+     * they are doing.
+     */
+}
+
 int libxl__domain_config_setdefault(libxl__gc *gc,
                                     libxl_domain_config *d_config,
                                     uint32_t domid)
@@ -974,6 +1000,20 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
         goto error_out;
     }
 
+    if (d_config->b_info.shadow_memkb == LIBXL_MEMKB_DEFAULT
+        && ok_to_default_memkb_in_create(gc))
+        d_config->b_info.shadow_memkb =
+            libxl_get_required_shadow_memory(d_config->b_info.max_memkb,
+                                             d_config->b_info.max_vcpus);
+
+    /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' */
+    if (d_config->b_info.iommu_memkb == LIBXL_MEMKB_DEFAULT
+        && ok_to_default_memkb_in_create(gc))
+        d_config->b_info.iommu_memkb =
+            (d_config->c_info.passthrough == LIBXL_PASSTHROUGH_SYNC_PT)
+            ? libxl_get_required_iommu_memory(d_config->b_info.max_memkb)
+            : 0;
+
     ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);
     if (ret) {
         LOGD(ERROR, domid, "Unable to set domain build info defaults");
tools/libxl/libxl_internal.h +3 -0
index 01de5576d9..0185b8ff01 100644
@@ -637,6 +637,9 @@ struct libxl__ctx {
     LIBXL_LIST_ENTRY(libxl_ctx) sigchld_users_entry;
 
     libxl_version_info version_info;
+
+    bool libxl_domain_need_memory_0x041200_called,
+         libxl_domain_need_memory_called;
 };
 
 /*
tools/libxl/libxl_mem.c +4 -0
index 6042299393..7c01fac7e5 100644
@@ -484,6 +484,8 @@ int libxl_domain_need_memory(libxl_ctx *ctx,
     GC_INIT(ctx);
     int rc;
 
+    ctx->libxl_domain_need_memory_called = 1;
+
     rc = libxl__domain_config_setdefault(gc,
                                          d_config,
                                          domid_for_logging);
@@ -507,6 +509,8 @@ int libxl_domain_need_memory_0x041200(libxl_ctx *ctx,
     GC_INIT(ctx);
     int rc;
 
+    ctx->libxl_domain_need_memory_0x041200_called = 1;
+
     libxl_domain_build_info b_info[1];
     libxl_domain_build_info_init(b_info);
     libxl_domain_build_info_copy(ctx, b_info, b_info_in);
tools/xl/xl_parse.c +2 -13
index 03a2c54dd2..79871c22d0 100644
@@ -1572,19 +1572,8 @@ void parse_config_data(const char *config_source,
         exit(-ERROR_FAIL);
     }
 
-    /* libxl_get_required_shadow_memory() and
-     * libxl_get_required_iommu_memory() must be called after final values
-     * (default or specified) for vcpus and memory are set, because the
-     * calculations depend on those values. */
-    b_info->shadow_memkb = !xlu_cfg_get_long(config, "shadow_memory", &l, 0)
-        ? l * 1024
-        : libxl_get_required_shadow_memory(b_info->max_memkb,
-                                           b_info->max_vcpus);
-
-    /* No IOMMU reservation is needed if passthrough mode is not 'sync_pt' */
-    b_info->iommu_memkb = (c_info->passthrough == LIBXL_PASSTHROUGH_SYNC_PT)
-        ? libxl_get_required_iommu_memory(b_info->max_memkb)
-        : 0;
+    if (!xlu_cfg_get_long(config, "shadow_memory", &l, 0))
+        b_info->shadow_memkb = l * 1024;
 
     xlu_cfg_get_defbool(config, "nomigrate", &b_info->disable_migrate, 0);
 
Signature · 7 lines
2.11.0


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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

Quoted 38 lines · Ian Jackson

Defaulting is supposed to be done by libxl. So these calculations should be here in libxl. libxl__domain_config_setdefault has all the necessary information including the values of max_memkb and max_vcpus.

The overall functional effect depends on the caller:

For xl, no change. The code moves from xl to libxl.

For callers who set one or both shadow_memkb and iommu_memkb (whether from libxl_get_required_shadow_memory or otherwise) before calling libxl_domain_need_memory (any version): the new code will leave their setting(s) unchanged.

For callers who do not call libxl_domain_need_memory at all, and who fail to set one of these memory values: now they are both are properly set. The shadow and iommu memory to be properly accounted for as intended.

For callers which call libxl_domain_need_memory and request the current API (4.13) or which track libxl, the default values are also now right and everything works as intended.

For callers which call libxl_domain_need_memory, and request an old pre-4.13 libxl API, and which leave one of these memkb settings unset, we take special measures to preserve the old behaviour.

This means that they don't get the additional iommu memory and are at risk of the domain running out of memory as a result of f89f555827a6 "remove late (on-demand) construction of IOMMU page tables". But this is no worse than the state just after f89f555827a6, which already broke such callers in that way. This is perhaps justifiable because of the API stability warning next to libxl_domain_need_memory.

An alternative would be to drop the special-casing of these callers. That would cause a discrepancy between libxl_domain_need_memory and
libxl_domain_create: the former would not include the iommu memory and the latter would. That seems worse, but it's debateable.

Quoted 4 lines

---
v2: Replace _Bool with bool
Fix logic sense in ok_to_default_memkb_in_create

Signature · 6 lines
Anthony PERARD

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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

For callers which call libxl_domain_need_memory, and request an old pre-4.13 libxl API, and which leave one of these memkb settings unset, we take special measures to preserve the old behaviour.

This means that they don't get the additional iommu memory and are at risk of the domain running out of memory as a result of f89f555827a6 "remove late (on-demand) construction of IOMMU page tables". But this is no worse than the state just after f89f555827a6, which already broke such callers in that way. This is perhaps justifiable because of the API stability warning next to libxl_domain_need_memory.

There's probably something else that is needed to be done for user of the pre-4.13 API. If they call libxl_domain_need_memory_0x041200, there is nothing that set iommu_memkb, so the default value stays at -1 and libxl_domain_need_memory_0x041200 returns a value that is lower that "target_memkb + shadow_memkb". Then, when libxl create the domain, it still keep iommu_memkb==-1, because the old API as been used.

I tried to have xl call the 4.12 API and create a guest without passthrough, and QEMU crashed (assert() failure).

So maybe libxl__domain_build_info_setdefault() should also set a value to iommu_memkb as it does for shadow_memkb? At least, set iommu_memkb=0 if still the default.

iommu_memkb is new in 4.13, user of the pre-4.13 API will not set it.

Signature · 6 lines
Anthony PERARD

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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

Anthony PERARD writes ("Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl"):

Quoted 7 lines

There's probably something else that is needed to be done for user of the pre-4.13 API. If they call libxl_domain_need_memory_0x041200, there is nothing that set iommu_memkb, so the default value stays at -1 and libxl_domain_need_memory_0x041200 returns a value that is lower that "target_memkb + shadow_memkb". Then, when libxl create the domain, it still keep iommu_memkb==-1, because the old API as been used.

Quoted 6 lines

I tried to have xl call the 4.12 API and create a guest without passthrough, and QEMU crashed (assert() failure).

So maybe libxl__domain_build_info_setdefault() should also set a value to iommu_memkb as it does for shadow_memkb? At least, set iommu_memkb=0 if still the default.

I think you are right. Not sure how I missed that.

Ian.

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

#5 lore raw

Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

In reply to Anthony PERARD

Anthony PERARD writes ("Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl"):

Quoted 3 lines

So maybe libxl__domain_build_info_setdefault() should also set a value to iommu_memkb as it does for shadow_memkb? At least, set iommu_memkb=0 if still the default.

I think, this.

Ian.

From 379d8eb69f713cccf7eacb4c2a63f4f5fe944255 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Mon, 14 Oct 2019 17:59:00 +0100
Subject: [PATCH] squash! libxl: Move shadow_memkb and iommu_memkb defaulting
into libxl

---
v4: Provide a fallback default for iommu_memkb too, for old callers.

---
 tools/libxl/libxl_create.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxl/libxl_create.c +4 -0
index 7423bedf7d..b3951a2423 100644
@@ -229,6 +229,10 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     libxl__arch_domain_build_info_setdefault(gc, b_info);
     libxl_defbool_setdefault(&b_info->dm_restrict, false);
 
+    if (b_info->iommu_memkb == LIBXL_MEMKB_DEFAULT)
+        /* Normally defaulted in libxl__domain_create_info_setdefault */
+        b_info->iommu_memkb = 0;
+
     switch (b_info->type) {
     case LIBXL_DOMAIN_TYPE_HVM:
         if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT)
Signature · 7 lines
2.11.0


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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl

Quoted 26 lines · Ian Jackson

Anthony PERARD writes ("Re: [Xen-devel] [XEN PATCH for-4.13 v3 05/10] libxl: Move shadow_memkb and iommu_memkb defaulting into libxl"):

Quoted 3 lines

So maybe libxl__domain_build_info_setdefault() should also set a value to iommu_memkb as it does for shadow_memkb? At least, set iommu_memkb=0 if still the default.

I think, this.

Ian.

From 379d8eb69f713cccf7eacb4c2a63f4f5fe944255 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Mon, 14 Oct 2019 17:59:00 +0100
Subject: [PATCH] squash! libxl: Move shadow_memkb and iommu_memkb defaulting
into libxl

---
v4: Provide a fallback default for iommu_memkb too, for old callers.

---
 tools/libxl/libxl_create.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/libxl/libxl_create.c +0 -0
index 7423bedf7d..b3951a2423 100644

tools/libxl/libxl_create.c int libxl__domain_build_info_setdefault(libxl__gc *gc, · line 238

Quoted 10 lines
tools/libxl/libxl_create.c +4 -0
@@ -229,6 +229,10 @@ int libxl__domain_build_info_setdefault(libxl__gc *gc,
     libxl__arch_domain_build_info_setdefault(gc, b_info);
     libxl_defbool_setdefault(&b_info->dm_restrict, false);
 
+    if (b_info->iommu_memkb == LIBXL_MEMKB_DEFAULT)
+        /* Normally defaulted in libxl__domain_create_info_setdefault */
+        b_info->iommu_memkb = 0;
+
     switch (b_info->type) {
     case LIBXL_DOMAIN_TYPE_HVM:
         if (b_info->shadow_memkb == LIBXL_MEMKB_DEFAULT)

Thanks,

Signature · 6 lines
Anthony PERARD

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

PATCH v3 6/10 libxl: Remove/deprecate libxl_get_required_*_memory from the API

In reply to Ian Jackson

These are now redundant because shadow_memkb and iommu_memkb are now defaulted automatically by libxl_domain_need_memory and libxl_domain_create etc. Callers should not now call these; instead, they should just let libxl take care of it.

libxl_get_required_shadow_memory was introduced in f89f555827a6
"remove late (on-demand) construction of IOMMU page tables"
We can freely remove it because it was never in any release.

libxl_get_required_shadow_memory has been in libxl approximately forever. It should probably not have survived the creation of libxl_domain_create, but it seems the API awkwardnesses we see in recent commits prevented this. So we have to keep it. It remains functional but we can deprecate it. Hopefully we can get rid of it completely before we find the need to change the calculation to use additional information which its arguments do not currently supply.

---
 tools/libxl/libxl_create.c | 17 ++++++++++++++++-
 tools/libxl/libxl_utils.c  | 15 ---------------
 tools/libxl/libxl_utils.h  |  2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)
tools/libxl/libxl_create.c +16 -1
index a1b00a8aef..b394312d98 100644
@@ -888,6 +888,21 @@ static bool ok_to_default_memkb_in_create(libxl__gc *gc)
      */
 }
 
+static unsigned long libxl__get_required_iommu_memory(unsigned long maxmem_kb)
+{
+    unsigned long iommu_pages = 0, mem_pages = maxmem_kb / 4;
+    unsigned int level;
+
+    /* Assume a 4 level page table with 512 entries per level */
+    for (level = 0; level < 4; level++)
+    {
+        mem_pages = DIV_ROUNDUP(mem_pages, 512);
+        iommu_pages += mem_pages;
+    }
+
+    return iommu_pages * 4;
+}
+
 int libxl__domain_config_setdefault(libxl__gc *gc,
                                     libxl_domain_config *d_config,
                                     uint32_t domid)
@@ -1011,7 +1026,7 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
         && ok_to_default_memkb_in_create(gc))
         d_config->b_info.iommu_memkb =
             (d_config->c_info.passthrough == LIBXL_PASSTHROUGH_SYNC_PT)
-            ? libxl_get_required_iommu_memory(d_config->b_info.max_memkb)
+            ? libxl__get_required_iommu_memory(d_config->b_info.max_memkb)
             : 0;
 
     ret = libxl__domain_build_info_setdefault(gc, &d_config->b_info);
tools/libxl/libxl_utils.c +0 -15
index 405733b7e1..f360f5e228 100644
@@ -48,21 +48,6 @@ unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned
     return 4 * (256 * smp_cpus + 2 * (maxmem_kb / 1024));
 }
 
-unsigned long libxl_get_required_iommu_memory(unsigned long maxmem_kb)
-{
-    unsigned long iommu_pages = 0, mem_pages = maxmem_kb / 4;
-    unsigned int level;
-
-    /* Assume a 4 level page table with 512 entries per level */
-    for (level = 0; level < 4; level++)
-    {
-        mem_pages = DIV_ROUNDUP(mem_pages, 512);
-        iommu_pages += mem_pages;
-    }
-
-    return iommu_pages * 4;
-}
-
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid)
 {
     unsigned int len;
tools/libxl/libxl_utils.h +1 -1
index 630ccbe28a..46918aea84 100644
@@ -24,7 +24,7 @@ const
 char *libxl_basename(const char *name); /* returns string from strdup */
 
 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
-unsigned long libxl_get_required_iommu_memory(unsigned long maxmem_kb);
+  /* deprecated; see LIBXL_HAVE_DOMAIN_NEED_MEMORY_CONFIG in libxl.h */
 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 int libxl_domain_qualifier_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
Signature · 7 lines
2.11.0


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

PATCH v3 7/10 libxl: create: setdefault: Make libxl_physinfo info[1]

In reply to Ian Jackson

No functional change. This will let us make it into a pointer without textual change other than to the definition.

While we are here, fix some style errors (missing { }).

---
v2: New patch in this version of the series.

---
 tools/libxl/libxl_create.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
tools/libxl/libxl_create.c +8 -8
index b394312d98..9c56a914ca 100644
@@ -30,10 +30,10 @@
 int libxl__domain_create_info_setdefault(libxl__gc *gc,
                                          libxl_domain_create_info *c_info)
 {
-    libxl_physinfo info;
+    libxl_physinfo info[1];
     int rc;
 
-    rc = libxl_get_physinfo(CTX, &info);
+    rc = libxl_get_physinfo(CTX, info);
     if (rc)
         return rc;
 
@@ -45,11 +45,11 @@ 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) {
-        if (info.cap_hap)
+        if (info->cap_hap) {
             libxl_defbool_setdefault(&c_info->hap, true);
-        else if (info.cap_shadow)
+        } else if (info->cap_shadow) {
             libxl_defbool_setdefault(&c_info->hap, false);
-        else {
+        } else {
             LOG(ERROR, "neither hap nor shadow paging available");
             return ERROR_INVAL;
         }
@@ -63,12 +63,12 @@ int libxl__domain_create_info_setdefault(libxl__gc *gc,
     if (!c_info->ssidref)
         c_info->ssidref = SECINITSID_DOMU;
 
-    if (info.cap_hvm_directio &&
+    if (info->cap_hvm_directio &&
         (c_info->passthrough == LIBXL_PASSTHROUGH_UNKNOWN)) {
         c_info->passthrough = ((c_info->type == LIBXL_DOMAIN_TYPE_PV) ||
-                               !info.cap_iommu_hap_pt_share) ?
+                               !info->cap_iommu_hap_pt_share) ?
             LIBXL_PASSTHROUGH_SYNC_PT : LIBXL_PASSTHROUGH_SHARE_PT;
-    } else if (!info.cap_hvm_directio) {
+    } else if (!info->cap_hvm_directio) {
         c_info->passthrough = LIBXL_PASSTHROUGH_DISABLED;
     }
 
Signature · 7 lines
2.11.0


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

PATCH v3 8/10 libxl: create: setdefault: Move physinfo into config_setdefault

In reply to Ian Jackson

No functional change. This will let us refer to it in code we are about to add to this function.

---
v2: New patch in this version of the series.

---
 tools/libxl/libxl_create.c   | 17 ++++++++---------
 tools/libxl/libxl_dm.c       |  7 ++++++-
 tools/libxl/libxl_internal.h |  3 ++-
 3 files changed, 16 insertions(+), 11 deletions(-)
tools/libxl/libxl_create.c +8 -9
index 9c56a914ca..69971c97b6 100644
@@ -28,15 +28,9 @@
 #include <xen-xsm/flask/flask.h>
 
 int libxl__domain_create_info_setdefault(libxl__gc *gc,
-                                         libxl_domain_create_info *c_info)
+                                         libxl_domain_create_info *c_info,
+                                         const libxl_physinfo *info)
 {
-    libxl_physinfo info[1];
-    int rc;
-
-    rc = libxl_get_physinfo(CTX, info);
-    if (rc)
-        return rc;
-
     if (!c_info->type) {
         LOG(ERROR, "domain type unspecified");
         return ERROR_INVAL;
@@ -911,6 +905,10 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
     int ret;
     bool pod_enabled = false;
 
+    libxl_physinfo physinfo;
+    ret = libxl_get_physinfo(CTX, &physinfo);
+    if (ret) goto error_out;
+
     if (d_config->c_info.ssid_label) {
         char *s = d_config->c_info.ssid_label;
         ret = libxl_flask_context_to_sid(ctx, s, strlen(s),
@@ -1009,7 +1007,8 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
         goto error_out;
     }
 
-    ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info);
+    ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info,
+                                               &physinfo);
     if (ret) {
         LOGD(ERROR, domid, "Unable to set domain create info defaults");
         goto error_out;
tools/libxl/libxl_dm.c +6 -1
index c00356a2f1..e6a48974f8 100644
@@ -2167,7 +2167,12 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
     dm_config->c_info.run_hotplug_scripts =
         guest_config->c_info.run_hotplug_scripts;
 
-    ret = libxl__domain_create_info_setdefault(gc, &dm_config->c_info);
+    libxl_physinfo physinfo;
+    ret = libxl_get_physinfo(CTX, &physinfo);
+    if (ret) goto out;
+
+    ret = libxl__domain_create_info_setdefault(gc, &dm_config->c_info,
+                                               &physinfo);
     if (ret) goto out;
     ret = libxl__domain_build_info_setdefault(gc, &dm_config->b_info);
     if (ret) goto out;
tools/libxl/libxl_internal.h +2 -1
index 0185b8ff01..6a614658c2 100644
@@ -1447,7 +1447,8 @@ _hidden int libxl__domain_config_setdefault(libxl__gc *gc,
                                             libxl_domain_config *d_config,
                                             uint32_t domid /* logging only */);
 _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc,
-                                        libxl_domain_create_info *c_info);
+                                        libxl_domain_create_info *c_info,
+                                        const libxl_physinfo *info);
 _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc,
                                         libxl_domain_build_info *b_info);
 _hidden void libxl__rdm_setdefault(libxl__gc *gc,
Signature · 7 lines
2.11.0


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

PATCH v3 9/10 libxl: Move domain_create_info_setdefault earlier

In reply to Ian Jackson

We need this before we start to figure out the passthrough mode.

I have checked that nothing in libxl__domain_create_info_setdefault nor the two implementations of ..._arch_... accesses anything else, other than (i) the domain type (which this function is responsible for setting and nothing before it looks at) (ii) c_info->ssidref (which is defaulted by flask code near the top of libxl__domain_config_setdefault and not accessed afterwards).

So no functional change.

---
v3: New patch in this version of the series.

---
 tools/libxl/libxl_create.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/libxl/libxl_create.c +7 -7
index 69971c97b6..3d2cb52bf7 100644
@@ -968,6 +968,13 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
         goto error_out;
     }
 
+    ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info,
+                                               &physinfo);
+    if (ret) {
+        LOGD(ERROR, domid, "Unable to set domain create info defaults");
+        goto error_out;
+    }
+
     /* If target_memkb is smaller than max_memkb, the subsequent call
      * to libxc when building HVM domain will enable PoD mode.
      */
@@ -1007,13 +1014,6 @@ int libxl__domain_config_setdefault(libxl__gc *gc,
         goto error_out;
     }
 
-    ret = libxl__domain_create_info_setdefault(gc, &d_config->c_info,
-                                               &physinfo);
-    if (ret) {
-        LOGD(ERROR, domid, "Unable to set domain create info defaults");
-        goto error_out;
-    }
-
     if (d_config->b_info.shadow_memkb == LIBXL_MEMKB_DEFAULT
         && ok_to_default_memkb_in_create(gc))
         d_config->b_info.shadow_memkb =
Signature · 7 lines
2.11.0


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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 09/10] libxl: Move domain_create_info_setdefault earlier

Quoted 9 lines · Ian Jackson

We need this before we start to figure out the passthrough mode.

I have checked that nothing in libxl__domain_create_info_setdefault nor the two implementations of ..._arch_... accesses anything else, other than (i) the domain type (which this function is responsible for setting and nothing before it looks at) (ii) c_info->ssidref (which is defaulted by flask code near the top of libxl__domain_config_setdefault and not accessed afterwards).

Quoted 3 lines

So no functional change.

Signature · 6 lines
Anthony PERARD

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

PATCH v3 10/10 libxl/xl: Overhaul passthrough setting logic

In reply to Ian Jackson

LIBXL_PASSTHROUGH_UNKNOWN (aka "ENABLED" in an earlier uncommitted version of this code) is doing double duty. We actually need all of the following to be specificable:
* default ("unspecified"): enable PT iff we have devices to pass through specified in the initial config file.
* "enabled" (and fail if the platform doesn't support it).
* "disabled" (and reject future PT hotplug).
* "share_pt"/"sync_pt": enable PT and set a specific PT mode.

Defaulting and error checking should be done in libxl. So, we make several changes here.

We introduce "enabled". (And we document "unspecified".)

We move all of the error checking and defaulting code from xl into libxl. Now, libxl__domain_config_setdefault has all of the necessary information to get this right. So we can do it all there. Choosing the specific mode is arch-specific.

We can also arrange to have only one place each which calculates
(i) whether passthrough needs to be enabled because pt devices were specified (ii) whether pt_share can be used (for each arch).

xl now only has to parse the enum in the same way as it parses all other enums.

This change fixes a regression from earlier 4.13-pre: until recent changes, passthrough was only enabled by default if passthrough devices were specified. We restore this behaviour.

CC Stefano Stabellini <[email protected]>
CC Julien Grall <[email protected]>
CC Volodymyr Babchuk <[email protected]>
CC Andrew Cooper <[email protected]>
CC Paul Durrant <[email protected]>
CC Jan Beulich <[email protected]>

---
v3: Drop paragraph about masking another osstest regression,
as that's now fixed.
Drop redundant "ERROR:" in two log messages.
Add a comment about the way "enabled" gets changed to a specific value. Split passthrough mode defaulting into arch specific functions. On ARM, always choose (and insist on) share_pt.
Reject share_pt for non-HAP guests.
Reject passthrough for PVH guests.
Actually document "unspecified" option in xl.cfg(5)
Rename "unknown" to "unspecified"

v2: New patch in this version of the series.

---
 docs/man/xl.cfg.5.pod.in    |  6 ++++
 tools/libxl/libxl_arch.h    |  6 ++++
 tools/libxl/libxl_arm.c     | 24 ++++++++++++++++
 tools/libxl/libxl_create.c  | 43 ++++++++++++++++++++---------
 tools/libxl/libxl_types.idl |  7 +++--
 tools/libxl/libxl_x86.c     | 41 +++++++++++++++++++++++++++
 tools/xl/xl_parse.c         | 67 ++++-----------------------------------------
 7 files changed, 116 insertions(+), 78 deletions(-)
docs/man/xl.cfg.5.pod.in +6 -0
index 64bed30bce..7e220d0c20 100644
@@ -660,6 +660,12 @@ in preference. However, the availability of this option is hardware
 specific. If B<xl info> reports B<virt_caps> containing
 B<iommu_hap_pt_share> then this option may be used.
 
+=item B<unspecified>
+
+The default, which chooses between B<disabled> and B<enabled>
+according to whether passthrough devices are enabled in the config
+file.
+
 =back
 
 =back
tools/libxl/libxl_arch.h +6 -0
index d624159e53..ee6641b3e6 100644
@@ -73,6 +73,12 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
                                               libxl_domain_build_info *b_info);
 
 _hidden
+int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc,
+                                            uint32_t domid,
+                                            libxl_domain_config *d_config,
+                                            const libxl_physinfo *physinfo);
+
+_hidden
 int libxl__arch_extra_memory(libxl__gc *gc,
                              const libxl_domain_build_info *info,
                              uint64_t *out);
tools/libxl/libxl_arm.c +24 -0
index bf31b9b3ca..2f1ca69431 100644
@@ -1191,6 +1191,30 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
     libxl_domain_build_info_init_type(b_info, LIBXL_DOMAIN_TYPE_PVH);
 }
 
+int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc,
+                                            uint32_t domid,
+                                            libxl_domain_config *d_config,
+                                            const libxl_physinfo *physinfo)
+{
+    int rc;
+    libxl_domain_create_info *const c_info = &d_config->c_info;
+
+    if (c_info->passthrough == LIBXL_PASSTHROUGH_ENABLED) {
+        c_info->passthrough = LIBXL_PASSTHROUGH_SHARE_PT;
+    }
+
+    if (c_info->passthrough == LIBXL_PASSTHROUGH_SYNC_PT) {
+        LOGD(ERROR, domid,
+             "passthrough=\"sync_pt\" not supported on ARM\n");
+        rc = ERROR_INVAL;
+        goto out;
+    }
+
+    rc = 0;
+ out:
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
tools/libxl/libxl_create.c +30 -13

67 lines not on this page · raw message

tools/libxl/libxl_types.idl +4 -3
index 3ac9494b80..2cb5a86b60 100644
@@ -264,10 +264,11 @@ libxl_vkb_backend = Enumeration("vkb_backend", [
     ])
 
 libxl_passthrough = Enumeration("passthrough", [
-    (0, "unknown"),
+    (0, "unspecified"),
     (1, "disabled"),
-    (2, "sync_pt"),
-    (3, "share_pt"),
+    (2, "enabled"), # becomes {sync,share}_pt once defaults are evaluated
+    (3, "sync_pt"),
+    (4, "share_pt"),
     ])
 
 #
tools/libxl/libxl_x86.c +41 -0

47 lines not on this page · raw message

tools/xl/xl_parse.c +5 -62

87 lines not on this page · raw message

Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v3 10/10
#13 lore raw

Re: [Xen-devel] [XEN PATCH for-4.13 v3 10/10] libxl/xl: Overhaul passthrough setting logic

Quoted 1 line · Ian Jackson

LIBXL_PASSTHROUGH_UNKNOWN (aka "ENABLED" in an earlier uncommitted

I guess that's now LIBXL_PASSTHROUGH_UNSPECIFIED.

Quoted 3 lines

version of this code) is doing double duty. We actually need all of the following to be specificable:
* default ("unspecified"): enable PT iff we have devices to

                                         ^if
Quoted 42 lines

pass through specified in the initial config file.
* "enabled" (and fail if the platform doesn't support it).
* "disabled" (and reject future PT hotplug).
* "share_pt"/"sync_pt": enable PT and set a specific PT mode.

Defaulting and error checking should be done in libxl. So, we make several changes here.

We introduce "enabled". (And we document "unspecified".)

We move all of the error checking and defaulting code from xl into libxl. Now, libxl__domain_config_setdefault has all of the necessary information to get this right. So we can do it all there. Choosing the specific mode is arch-specific.

We can also arrange to have only one place each which calculates
(i) whether passthrough needs to be enabled because pt devices were specified (ii) whether pt_share can be used (for each arch).

xl now only has to parse the enum in the same way as it parses all other enums.

This change fixes a regression from earlier 4.13-pre: until recent changes, passthrough was only enabled by default if passthrough devices were specified. We restore this behaviour.

---

tools/libxl/libxl_x86.c +5 -0
index c0f88a7eaa..226b712cbd 100644
@@ -631,6 +631,47 @@ void libxl__arch_domain_build_info_setdefault(libxl__gc *gc,
     libxl_defbool_setdefault(&b_info->acpi, true);
 }
 
+int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc,
+                                            uint32_t domid,
+                                            libxl_domain_config *d_config,
+                                            const libxl_physinfo *physinfo)
+{

[...]

tools/libxl/libxl_x86.c

Quoted 2 lines
tools/libxl/libxl_x86.c +2 -0
+}
+                                        

There are 40 trailing white space here, any reason? :-).

Beside a few typos, the patch looks fine to me:

Signature · 6 lines
Anthony PERARD

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

Re: [Xen-devel] [XEN PATCH for-4.13 v3 10/10] libxl/xl: Overhaul passthrough setting logic

Anthony PERARD writes ("Re: [Xen-devel] [XEN PATCH for-4.13 v3 10/10] libxl/xl: Overhaul passthrough setting logic"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

LIBXL_PASSTHROUGH_UNKNOWN (aka "ENABLED" in an earlier uncommitted

I guess that's now LIBXL_PASSTHROUGH_UNSPECIFIED.

Heh, see my other mail, just crossed with yours.

Quoted 8 lines
Quoted 5 lines
tools/libxl/libxl_arm.c +5 -0
+int libxl__arch_passthrough_mode_setdefault(libxl__gc *gc,
+                                            uint32_t domid,
+                                            libxl_domain_config *d_config,
+                                            const libxl_physinfo *physinfo)
+{

[...]

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+}
+                                        

There are 40 trailing white space here, any reason? :-).

No. I will get rid of them. My editor doesn't complain about them and my personal view is that this is pointless bureaucracy but it's not just up to me, so I'll fix it.

Quoted 2 lines

Beside a few typos, the patch looks fine to me:

Thanks.

If I change "unspecified" back to "unknown", and fix the spaces (and I'll have a look for typos), should I retain your ack ?

Thanks,
Ian.

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