Skip to contentSkip to conversation

Rationalize max_grant_frames and max_maptrack_frames handling

PATCH Superseded Paul Durrant 7 participants 20 messages Nov 28, 2019 – Nov 29, 2019 Arm/actions semi architecture

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 Rationalize max_grant_frames and max_maptrack_frames handling

From: George Dunlap <[email protected]>

Xen used to have single, system-wide limits for the number of grant frames and maptrack frames a guest was allowed to create. Increasing or decreasing this single limit on the Xen command-line would change the limit for all guests on the system.

Later, per-domain limits for these values was created. The system-wide limits became strict limits: domains could not be created with higher limits, but could be created with lower limits. However, that change also introduced a range of different "default" values into various places in the toolstack:

- The python libxc bindings hard-coded these values to 32 and 1024, respectively
- The libxl default values are 32 and 1024 respectively.
- xl will use the libxl default for maptrack, but does its own default calculation for grant frames: either 32 or 64, based on the max possible mfn.

These defaults interact poorly with the hypervisor command-line limit:

- The hypervisor command-line limit cannot be used to raise the limit for all guests anymore, as the default in the toolstack will effectively override this.
- If you use the hypervisor command-line limit to *reduce* the limit, then the "default" values generated by the toolstack are too high, and all guest creations will fail.

In other words, the toolstack defaults require any change to be effected by having the admin explicitly specify a new value in every guest.

In order to address this, have grant_table_init treat negative values for max_grant_frames and max_maptrack_frames as instructions to use the system-wide default, and have all the above toolstacks default to passing -1 unless a different value is explicitly configured.

This restores the old behavior in that changing the hypervisor command-line option can change the behavior for all guests, while retaining the ability to set per-guest values. It also removes the bug that reducing the system-wide max will cause all domains without explicit limits to fail.

NOTE: - The Ocaml bindings require the caller to always specify a value,
and the code to start a xenstored stubdomain hard-codes these to 4 and 128 respectively; this behavour will not be modified.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: "Marek Marczykowski-Górecki" <[email protected]>
Cc: Volodymyr Babchuk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

v5:
- Remove erroneous __init annotations
- Fail out of range command line values with ERANGE
- Make opt_max_maptrack_frames static

v4:
- Add missing braces in xlu_cfg_get_bounded_long()

v3:
- Make sure that specified values cannot be negative or overflow a signed int

v2:
- re-worked George's original commit massage a little
- fixed the text in xl.conf.5.pod
- use -1 as the sentinel value for 'default' and < 0 for checking it

---
 docs/man/xl.conf.5.pod            |  6 +++--
 tools/libxl/libxl.h               |  4 +--
 tools/libxl/libxl_types.idl       |  4 +--
 tools/libxl/libxlu_cfg.c          | 26 ++++++++++++++++--
 tools/libxl/libxlutil.h           |  2 ++
 tools/python/xen/lowlevel/xc/xc.c |  4 +--
 tools/xl/xl.c                     | 15 ++++-------
 tools/xl/xl_parse.c               |  9 ++++---
 xen/arch/arm/setup.c              |  2 +-
 xen/arch/x86/setup.c              |  4 +--
 xen/common/grant_table.c          | 45 +++++++++++++++++++++++++++----
 xen/include/public/domctl.h       | 10 ++++---
 xen/include/xen/grant_table.h     | 10 +++----
 13 files changed, 100 insertions(+), 41 deletions(-)
docs/man/xl.conf.5.pod +4 -2
index 962144e38e..207ab3e77a 100644
@@ -81,13 +81,15 @@ Default: C</var/lock/xl>
 
 Sets the default value for the C<max_grant_frames> domain config value.
 
-Default: C<32> on hosts up to 16TB of memory, C<64> on hosts larger than 16TB
+Default: value of Xen command line B<gnttab_max_frames> parameter (or its
+default value if unspecified).
 
 =item B<max_maptrack_frames=NUMBER>
 
 Sets the default value for the C<max_maptrack_frames> domain config value.
 
-Default: C<1024>
+Default: value of Xen command line B<gnttab_max_maptrack_frames>
+parameter (or its default value if unspecified).
 
 =item B<vif.default.script="PATH">
 
tools/libxl/libxl.h +2 -2
index 49b56fa1a3..a2a5d321c5 100644
@@ -364,8 +364,8 @@
  */
 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
 
-#define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32
-#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024
+#define LIBXL_MAX_GRANT_FRAMES_DEFAULT -1
+#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT -1
 
 /*
  * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
tools/libxl/libxl_types.idl +2 -2
index 0546d7865a..63e29bb2fb 100644
@@ -511,8 +511,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")),
 
-    ("max_grant_frames",    uint32, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
-    ("max_maptrack_frames", uint32, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),
+    ("max_grant_frames",    integer, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
+    ("max_maptrack_frames", integer, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),
     
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", libxl_defbool),
tools/libxl/libxlu_cfg.c +24 -2
index 72815d25dd..cafc632fc1 100644
@@ -268,8 +268,9 @@ int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n,
     return 0;
 }
 
-int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
-                     long *value_r, int dont_warn) {
+int xlu_cfg_get_bounded_long(const XLU_Config *cfg, const char *n,
+                             long min, long max, long *value_r,
+                             int dont_warn) {
     long l;
     XLU_ConfigSetting *set;
     int e;
@@ -303,10 +304,31 @@ int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
                     cfg->config_source, set->lineno, n);
         return EINVAL;
     }
+    if (l < min) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is smaller than minimum bound '%ld'\n",
+                    cfg->config_source, set->lineno, l, min);
+        return EINVAL;
+    }
+    if (l > max) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is greater than maximum bound '%ld'\n",
+                    cfg->config_source, set->lineno, l, max);
+        return EINVAL;
+    }
+
     *value_r= l;
     return 0;
 }
 
+int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
+                     long *value_r, int dont_warn) {
+    return xlu_cfg_get_bounded_long(cfg, n, LONG_MIN, LONG_MAX, value_r,
+                                    dont_warn);
+}
+
 int xlu_cfg_get_defbool(const XLU_Config *cfg, const char *n, libxl_defbool *b,
                      int dont_warn)
 {
tools/libxl/libxlutil.h +2 -0
index 057cc25cb2..92e35c5462 100644
@@ -63,6 +63,8 @@ int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n,
                            char **value_r, int dont_warn);
 int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r,
                      int dont_warn);
+int xlu_cfg_get_bounded_long(const XLU_Config*, const char *n, long min,
+                             long max, long *value_r, int dont_warn);
 int xlu_cfg_get_defbool(const XLU_Config*, const char *n, libxl_defbool *b,
                      int dont_warn);
 
tools/python/xen/lowlevel/xc/xc.c +2 -2
index 44d3606141..a751e85910 100644
@@ -127,8 +127,8 @@ static PyObject *pyxc_domain_create(XcObject *self,
         },
         .max_vcpus = 1,
         .max_evtchn_port = -1, /* No limit. */
-        .max_grant_frames = 32,
-        .max_maptrack_frames = 1024,
+        .max_grant_frames = -1,
+        .max_maptrack_frames = -1,
     };
 
     static char *kwd_list[] = { "domid", "ssidref", "handle", "flags",
tools/xl/xl.c +5 -10
index ddd29b3f1b..921c64f5ed 100644
@@ -23,6 +23,7 @@
 #include <ctype.h>
 #include <inttypes.h>
 #include <regex.h>
+#include <limits.h>
 
 #include <libxl.h>
 #include <libxl_utils.h>
@@ -96,7 +97,6 @@ static void parse_global_config(const char *configfile,
     XLU_Config *config;
     int e;
     const char *buf;
-    libxl_physinfo physinfo;
 
     config = xlu_cfg_init(stderr, configfile);
     if (!config) {
@@ -197,16 +197,11 @@ static void parse_global_config(const char *configfile,
     xlu_cfg_replace_string (config, "colo.default.proxyscript",
         &default_colo_proxy_script, 0);
 
-    if (!xlu_cfg_get_long (config, "max_grant_frames", &l, 0))
+    if (!xlu_cfg_get_bounded_long (config, "max_grant_frames", 0, INT_MAX,
+                                   &l, 0))
         max_grant_frames = l;
-    else {
-        libxl_physinfo_init(&physinfo);
-        max_grant_frames = (libxl_get_physinfo(ctx, &physinfo) != 0 ||
-                            !(physinfo.max_possible_mfn >> 32))
-                           ? 32 : 64;
-        libxl_physinfo_dispose(&physinfo);
-    }
-    if (!xlu_cfg_get_long (config, "max_maptrack_frames", &l, 0))
+    if (!xlu_cfg_get_bounded_long (config, "max_maptrack_frames", 0,
+                                   INT_MAX, &l, 0))
         max_maptrack_frames = l;
 
     libxl_cpu_bitmap_alloc(ctx, &global_vm_affinity_mask, 0);
tools/xl/xl_parse.c +6 -3
index 112f8ee026..555991dae3 100644
@@ -1411,13 +1411,16 @@ void parse_config_data(const char *config_source,
         !xlu_cfg_get_string (config, "cpus_soft", &buf, 0))
         parse_vcpu_affinity(b_info, cpus, buf, num_cpus, false);
 
-    if (!xlu_cfg_get_long (config, "max_grant_frames", &l, 0))
+    if (!xlu_cfg_get_bounded_long (config, "max_grant_frames", 0, INT_MAX,
+                                   &l, 0))
         b_info->max_grant_frames = l;
     else
         b_info->max_grant_frames = max_grant_frames;
-    if (!xlu_cfg_get_long (config, "max_maptrack_frames", &l, 0))
+
+    if (!xlu_cfg_get_bounded_long (config, "max_maptrack_frames", 0,
+                                   INT_MAX, &l, 0))
         b_info->max_maptrack_frames = l;
-    else if (max_maptrack_frames != -1)
+    else
         b_info->max_maptrack_frames = max_maptrack_frames;
 
     libxl_defbool_set(&b_info->claim_mode, claim_mode);
xen/arch/arm/setup.c +1 -1
index 51d32106b7..3c899cd4a0 100644
@@ -789,7 +789,7 @@ void __init start_xen(unsigned long boot_phys_offset,
         .flags = XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap,
         .max_evtchn_port = -1,
         .max_grant_frames = gnttab_dom0_frames(),
-        .max_maptrack_frames = opt_max_maptrack_frames,
+        .max_maptrack_frames = -1,
     };
     int rc;
 
xen/arch/x86/setup.c +2 -2
index 00ee87bde5..7d27f36053 100644
@@ -697,8 +697,8 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     struct xen_domctl_createdomain dom0_cfg = {
         .flags = IS_ENABLED(CONFIG_TBOOT) ? XEN_DOMCTL_CDF_s3_integrity : 0,
         .max_evtchn_port = -1,
-        .max_grant_frames = opt_max_grant_frames,
-        .max_maptrack_frames = opt_max_maptrack_frames,
+        .max_grant_frames = -1,
+        .max_maptrack_frames = -1,
     };
 
     /* Critical region without IDT or TSS.  Any fault is deadly! */
xen/common/grant_table.c +40 -5

63 lines not on this page · raw message

xen/include/public/domctl.h +6 -4
index 9f2cfd602c..e313da499f 100644
@@ -82,13 +82,15 @@ struct xen_domctl_createdomain {
     uint32_t iommu_opts;
 
     /*
-     * Various domain limits, which impact the quantity of resources (global
-     * mapping space, xenheap, etc) a guest may consume.
+     * Various domain limits, which impact the quantity of resources
+     * (global mapping space, xenheap, etc) a guest may consume.  For
+     * max_grant_frames and max_maptrack_frames, < 0 means "use the
+     * default maximum value in the hypervisor".
      */
     uint32_t max_vcpus;
     uint32_t max_evtchn_port;
-    uint32_t max_grant_frames;
-    uint32_t max_maptrack_frames;
+    int32_t max_grant_frames;
+    int32_t max_maptrack_frames;
 
     struct xen_arch_domainconfig arch;
 };
xen/include/xen/grant_table.h +4 -6
index 6f9345d9ef..98603604b8 100644
@@ -33,11 +33,10 @@
 struct grant_table;
 
 extern unsigned int opt_max_grant_frames;
-extern unsigned int opt_max_maptrack_frames;
 
 /* Create/destroy per-domain grant table context. */
-int grant_table_init(struct domain *d, unsigned int max_grant_frames,
-                     unsigned int max_maptrack_frames);
+int grant_table_init(struct domain *d, int max_grant_frames,
+                     int max_maptrack_frames);
 void grant_table_destroy(
     struct domain *d);
 void grant_table_init_vcpu(struct vcpu *v);
@@ -65,11 +64,10 @@ int gnttab_get_status_frame(struct domain *d, unsigned long idx,
 #else
 
 #define opt_max_grant_frames 0
-#define opt_max_maptrack_frames 0
 
 static inline int grant_table_init(struct domain *d,
-                                   unsigned int max_grant_frames,
-                                   unsigned int max_maptrack_frames)
+                                   int max_grant_frames,
+                                   int max_maptrack_frames)
 {
     return 0;
 }
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v5 1/1
#1 lore raw
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore. With this fixed (and no new issues introduced ;-) ) hypervisor side

As an additional remark (not for this patch) - the original wrong use of __init in v4 could have been replaced by __cold. But I guess we may want to consider adding such in a wider fashion.

Jan

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

#2 lore raw
Quoted 25 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore. With this fixed (and no new issues introduced ;-) ) hypervisor side

Quoted 1 line

And I guess I should have clarified: I'd be fine adding the missing assignment while committing, provided the tools side won't require any changes.

Jan

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

#3 lore raw
Quoted 16 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 29 November 2019 10:29
To: Durrant, Paul <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; George Dunlap <[email protected]>; Roger Pau Monné <[email protected]>; Volodymyr Babchuk <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Quoted 25 lines
Quoted 24 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore.

That was intentional, given Juergen's comment...

Quoted 7 lines

With this fixed (and no new

Quoted 2 lines

issues introduced ;-) ) hypervisor side

And I guess I should have clarified: I'd be fine adding the missing assignment while committing, provided the tools side won't require any changes.

...but if we want to allow dom0 to set itself up for INT_MAX frames in the event of a bad value then I'm not objecting.

Paul

Quoted 2 lines

Jan

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

#4 lore raw
Quoted 48 lines · Paul
Quoted 16 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 29 November 2019 10:29
To: Durrant, Paul <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; George Dunlap <[email protected]>; Roger Pau Monné <[email protected]>; Volodymyr Babchuk <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Quoted 25 lines
Quoted 24 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore.

That was intentional, given Juergen's comment...

Quoted 4 lines

With this fixed (and no new

Quoted 2 lines

issues introduced ;-) ) hypervisor side

Quoted 6 lines
Quoted 3 lines

And I guess I should have clarified: I'd be fine adding the missing assignment while committing, provided the tools side won't require any changes.

...but if we want to allow dom0 to set itself up for INT_MAX frames in the event of a bad value then I'm not objecting.

Looks like you're misunderstanding, or I'm missing something:
The command line options right now won't take any effect, as the opt_* global variables won't be written to at all. I'm not taking about falling back to using INT_MAX when we've noticed an out of bounds value.

Jan

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

#5 lore raw
Quoted 71 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 29 November 2019 10:46
To: Durrant, Paul <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; George Dunlap <[email protected]>; Roger Pau Monné <[email protected]>; Volodymyr Babchuk <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Konrad Rzeszutek Wilk <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Quoted 8 lines · Paul
Quoted 8 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 29 November 2019 10:29
To: Durrant, Paul <[email protected]>
Cc: Andrew Cooper <[email protected]>; Anthony PERARD <[email protected]>; George Dunlap <[email protected]>; Roger Pau Monné <[email protected]>; Volodymyr Babchuk <[email protected]>; George Dunlap

<[email protected]>;

Quoted 3 lines
Quoted 3 lines

Ian Jackson <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Stefano Stabellini <[email protected]>; [email protected]; Konrad

Rzeszutek

Quoted 41 lines
Quoted 5 lines

Wilk <[email protected]>; Julien Grall <[email protected]>; Wei Liu <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Quoted 25 lines
Quoted 24 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
     struct grant_table_arch arch;
 };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore.

That was intentional, given Juergen's comment...

Quoted 7 lines

With this fixed (and no new

Quoted 2 lines

issues introduced ;-) ) hypervisor side

And I guess I should have clarified: I'd be fine adding the missing assignment while committing, provided the tools side won't require any changes.

Quoted 8 lines
Quoted 2 lines

...but if we want to allow dom0 to set itself up for INT_MAX frames in the event of a bad value then I'm not objecting.

Looks like you're misunderstanding, or I'm missing something:
The command line options right now won't take any effect, as the opt_* global variables won't be written to at all. I'm not taking about falling back to using INT_MAX when we've noticed an out of bounds value.

Oh, sorry... too deep with my cutting. Yes, of course there should be a '*valp = val' just above 'return 0'.

Paul

Quoted 2 lines

Jan

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

#6 lore raw
In reply to Jan Beulich
Quoted 25 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
      struct grant_table_arch arch;
  };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore. With this fixed (and no new issues introduced ;-) ) hypervisor side

Quoted 1 line

And:

Juergen

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

#7 lore raw
Quoted 28 lines · Jürgen Groß
Quoted 25 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
      struct grant_table_arch arch;
  };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore. With this fixed (and no new issues introduced ;-) ) hypervisor side

Quoted 1 line
Quoted 3 lines

And:

Noted, but - ahead of a tool stack side ack? I.e. valid indefinitely no matter when that one would arrive?

Jan

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

#8 lore raw
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Jürgen Groß
Quoted 26 lines · Jan Beulich
Quoted 11 lines · Paul Durrant
xen/common/grant_table.c +5 -0
@@ -84,11 +84,40 @@ struct grant_table {
       struct grant_table_arch arch;
   };
 
+static int parse_gnttab_limit(const char *param, const char *arg,
+                              unsigned int *valp)
+{
+    const char *e;
+    unsigned long val;

xen/common/grant_table.c struct grant_table { · line 101

Quoted 10 lines
xen/common/grant_table.c +10 -0
+
+    val = simple_strtoul(arg, &e, 0);
+    if ( *e )
+        return -EINVAL;
+
+    if ( val > INT_MAX )
+        return -ERANGE;
+
+    return 0;
+}

*valp doesn't get written to anymore. With this fixed (and no new issues introduced ;-) ) hypervisor side

Quoted 6 lines
Quoted 3 lines

And:

Noted, but - ahead of a tool stack side ack? I.e. valid indefinitely no matter when that one would arrive?

We agreed this one to be a blocker, right?

Nevertheless: tools maintainers, please?

Juergen

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

#9 lore raw
In reply to Paul Durrant
Quoted 137 lines · Paul Durrant

From: George Dunlap <[email protected]>

Xen used to have single, system-wide limits for the number of grant frames and maptrack frames a guest was allowed to create. Increasing or decreasing this single limit on the Xen command-line would change the limit for all guests on the system.

Later, per-domain limits for these values was created. The system-wide limits became strict limits: domains could not be created with higher limits, but could be created with lower limits. However, that change also introduced a range of different "default" values into various places in the toolstack:

- The python libxc bindings hard-coded these values to 32 and 1024, respectively
- The libxl default values are 32 and 1024 respectively.
- xl will use the libxl default for maptrack, but does its own default calculation for grant frames: either 32 or 64, based on the max possible mfn.

These defaults interact poorly with the hypervisor command-line limit:

- The hypervisor command-line limit cannot be used to raise the limit for all guests anymore, as the default in the toolstack will effectively override this.
- If you use the hypervisor command-line limit to *reduce* the limit, then the "default" values generated by the toolstack are too high, and all guest creations will fail.

In other words, the toolstack defaults require any change to be effected by having the admin explicitly specify a new value in every guest.

In order to address this, have grant_table_init treat negative values for max_grant_frames and max_maptrack_frames as instructions to use the system-wide default, and have all the above toolstacks default to passing -1 unless a different value is explicitly configured.

This restores the old behavior in that changing the hypervisor command-line option can change the behavior for all guests, while retaining the ability to set per-guest values. It also removes the bug that reducing the system-wide max will cause all domains without explicit limits to fail.

NOTE: - The Ocaml bindings require the caller to always specify a value,
and the code to start a xenstored stubdomain hard-codes these to 4 and 128 respectively; this behavour will not be modified.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony PERARD <[email protected]>
Cc: "Marek Marczykowski-Górecki" <[email protected]>
Cc: Volodymyr Babchuk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

v5:
- Remove erroneous __init annotations
- Fail out of range command line values with ERANGE
- Make opt_max_maptrack_frames static

v4:
- Add missing braces in xlu_cfg_get_bounded_long()

v3:
- Make sure that specified values cannot be negative or overflow a signed int

v2:
- re-worked George's original commit massage a little
- fixed the text in xl.conf.5.pod
- use -1 as the sentinel value for 'default' and < 0 for checking it

---
 docs/man/xl.conf.5.pod            |  6 +++--
 tools/libxl/libxl.h               |  4 +--
 tools/libxl/libxl_types.idl       |  4 +--
 tools/libxl/libxlu_cfg.c          | 26 ++++++++++++++++--
 tools/libxl/libxlutil.h           |  2 ++
 tools/python/xen/lowlevel/xc/xc.c |  4 +--
 tools/xl/xl.c                     | 15 ++++-------
 tools/xl/xl_parse.c               |  9 ++++---
 xen/arch/arm/setup.c              |  2 +-
 xen/arch/x86/setup.c              |  4 +--
 xen/common/grant_table.c          | 45 +++++++++++++++++++++++++++----
 xen/include/public/domctl.h       | 10 ++++---
 xen/include/xen/grant_table.h     | 10 +++----
 13 files changed, 100 insertions(+), 41 deletions(-)
docs/man/xl.conf.5.pod +4 -2
index 962144e38e..207ab3e77a 100644
@@ -81,13 +81,15 @@ Default: C</var/lock/xl>
 
 Sets the default value for the C<max_grant_frames> domain config value.
 
-Default: C<32> on hosts up to 16TB of memory, C<64> on hosts larger than 16TB
+Default: value of Xen command line B<gnttab_max_frames> parameter (or its
+default value if unspecified).
 
 =item B<max_maptrack_frames=NUMBER>
 
 Sets the default value for the C<max_maptrack_frames> domain config value.
 
-Default: C<1024>
+Default: value of Xen command line B<gnttab_max_maptrack_frames>
+parameter (or its default value if unspecified).
 
 =item B<vif.default.script="PATH">
 
tools/libxl/libxl.h +2 -2
index 49b56fa1a3..a2a5d321c5 100644
@@ -364,8 +364,8 @@
  */
 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
 
-#define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32
-#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024
+#define LIBXL_MAX_GRANT_FRAMES_DEFAULT -1
+#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT -1
 
 /*
  * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
tools/libxl/libxl_types.idl +0 -0
index 0546d7865a..63e29bb2fb 100644

tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 515

Quoted 7 lines
tools/libxl/libxl_types.idl +2 -2
@@ -511,8 +511,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")),
 
-    ("max_grant_frames",    uint32, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
-    ("max_maptrack_frames", uint32, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),
+    ("max_grant_frames",    integer, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
+    ("max_maptrack_frames", integer, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),

What if we use 0xffffffff to denote default instead? That wouldn't require changing the type here.

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

If the decision is to change the type, please provide a #define in libxl.h.

Ian and Anthony, your opinion?

Wei.

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

#10 lore raw

Wei Liu writes ("Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 2 lines

What if we use 0xffffffff to denote default instead? That wouldn't require changing the type here.

Is there some reason we wouldn't use ~0 to mean default ?

In the tools area we normally spell this as
~(some appropriate type)0
to make sure it has the right width. But if we know the type and it is of fixed length, as here, 0xffffffffu is OK too.

Quoted 3 lines

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

The problem with the type change is that in principle we have to audit all the places the variables are used.

Ian.

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

#11 lore raw
Quoted 27 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Sent: 29 November 2019 15:47
To: Wei Liu <[email protected]>
Cc: Durrant, Paul <[email protected]>; Anthony Perard <[email protected]>; [email protected]; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Volodymyr Babchuk <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Wei Liu writes ("Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 2 lines

What if we use 0xffffffff to denote default instead? That wouldn't require changing the type here.

Is there some reason we wouldn't use ~0 to mean default ?

In the tools area we normally spell this as
~(some appropriate type)0
to make sure it has the right width. But if we know the type and it is of fixed length, as here, 0xffffffffu is OK too.

Quoted 7 lines
Quoted 3 lines

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

The problem with the type change is that in principle we have to audit all the places the variables are used.

Can a toolstack maintainer please come up with a concrete suggestion as to what the patch should do then? It's now at v6 and time is short.

Paul

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

#12 lore raw

Durrant, Paul writes ("RE: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 2 lines
Quoted 2 lines

-----Original Message-----
From: Ian Jackson <[email protected]>

...

Quoted 7 lines
Quoted 7 lines

Is there some reason we wouldn't use ~0 to mean default ?

In the tools area we normally spell this as
~(some appropriate type)0
to make sure it has the right width. But if we know the type and it is of fixed length, as here, 0xffffffffu is OK too.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

The problem with the type change is that in principle we have to audit all the places the variables are used.

Can a toolstack maintainer please come up with a concrete suggestion as to what the patch should do then? It's now at v6 and time is short.

I think our proposal is to drop the type change, continue to use uint32_t everwhere for these values, and specify the "use default" value to be all-bits-set.

Ian.

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

#13 lore raw
Quoted 19 lines · Ian Jackson

Durrant, Paul writes ("RE: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 2 lines
Quoted 2 lines

-----Original Message-----
From: Ian Jackson <[email protected]>

...

Quoted 11 lines
Quoted 11 lines

Is there some reason we wouldn't use ~0 to mean default ?

In the tools area we normally spell this as
~(some appropriate type)0
to make sure it has the right width. But if we know the type and it is of fixed length, as here, 0xffffffffu is OK too.

Quoted 3 lines

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The problem with the type change is that in principle we have to audit all the places the variables are used.

Can a toolstack maintainer please come up with a concrete suggestion as to what the patch should do then? It's now at v6 and time is short.

I think our proposal is to drop the type change, continue to use uint32_t everwhere for these values, and specify the "use default" value to be all-bits-set.

I tried to suggest something like this, but Jan didn’t like it for some reason.

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

#14 lore raw
In reply to Ian Jackson
Quoted 34 lines

-----Original Message-----
From: Ian Jackson <[email protected]>
Sent: 29 November 2019 16:08
To: Durrant, Paul <[email protected]>
Cc: Wei Liu <[email protected]>; Anthony Perard <[email protected]>; xen- [email protected]; George Dunlap <[email protected]>; Andrew Cooper <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Volodymyr Babchuk <[email protected]>; Roger Pau Monne <[email protected]>
Subject: RE: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Durrant, Paul writes ("RE: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 2 lines
Quoted 2 lines

-----Original Message-----
From: Ian Jackson <[email protected]>

...

Quoted 14 lines
Quoted 13 lines

Is there some reason we wouldn't use ~0 to mean default ?

In the tools area we normally spell this as
~(some appropriate type)0
to make sure it has the right width. But if we know the type and it is of fixed length, as here, 0xffffffffu is OK too.

Quoted 3 lines

The type change here makes me feel a bit uncomfortable, though in practice it may not matter. I don't see anyone would specify a value that would become negative when cast from uint32 to integer.

The problem with the type change is that in principle we have to audit all the places the variables are used.

Quoted 7 lines
Quoted 1 line

Can a toolstack maintainer please come up with a concrete suggestion as

to what the patch should do then? It's now at v6 and time is short.

I think our proposal is to drop the type change, continue to use uint32_t everwhere for these values, and specify the "use default" value to be all-bits-set.

Where? Everywhere or just in buildinfo? The switch from uint32_t to int32_t in the domctl does not, of course, change the width at all.

Paul

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

#15 lore raw
In reply to Ian Jackson

Ian Jackson writes ("RE: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling"):

Quoted 3 lines

I think our proposal is to drop the type change, continue to use uint32_t everwhere for these values, and specify the "use default" value to be all-bits-set.

Following discussion on IRC:

I think we toolstack maintainers do not think it right to change the type anywhere, but the hypervisor API/ABI is outside our bailiwick.

Changing the type in the libxl API is definitely undesirable in this patch, especially as we will want to backport it. Changing the type can cause compile errors in callers (who are out of tree), or even wrong behaviours.

We (Anthony and I, at least, having discussed it) feel that the libxl_types.idl type should remain unchanged.

Furthermore, in the existing libxl API, LIBXL_MAX_GRANT_FRAMES_DEFAULT and LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT have concrete values. Callers may have developed code which does something like LIBXL_MAX_GRANT_FRAMES_DEFAULT*4 to avoid the max_grant_frames issue. We need to keep those callers working.

I think the best way to do this is to retain those #defines with their existing values, but to decouple them. Instead, we provide a new #define for the sentinel value and change the init_val in the IDL to refer to that.

The effect is that callers who use _DEFAULT explicitly will see no change (and the only reason to do that would probably be to increase it as a bug workaround). Callers who do not set the value at all will get the sentinel value from init, which gets passed to the hypervisor and used as the default.

(In principle callers might call _init on the domain config and then modify the value they get, but I think that is both not entirely reasonable and quite unlikely. I think fixing this issue for others callers is more important.)

To demonstrate exactly what I mean here is a delta which can be squashed into v6.

Ian.

From 86d6e3b6e5434f0d872a195ed457a4af25a00208 Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Fri, 29 Nov 2019 16:51:45 +0000
Subject: [PATCH] squash! Rationalize max_grant_frames and max_maptrack_frames
handling

---
v7: Do not change type of libxl fields.
Do not change values of LIBXL_MAX_GRANT_FRAMES_DEFAULT etc. in case someone has done LIBXL_MAX_GRANT_FRAMES_DEFAULT*4. Deprecate those and provide LIBXL_MAX_GRANT_DEFAULT instead.

---
 tools/libxl/libxl.h         | 16 +++++++++-------
 tools/libxl/libxl_types.idl |  4 ++--
 2 files changed, 11 insertions(+), 9 deletions(-)
tools/libxl/libxl.h +9 -7
index b829c1bbce..54abb9db1f 100644
@@ -364,15 +364,17 @@
  */
 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
 
+#define LIBXL_MAX_GRANT_DEFAULT (~(uint32_t)0)
+#define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32 /* deprecated */
+#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024 /* deprecated */
 /*
- * LIBXL_HAVE_BUILDINFO_SIGNED_GRANT_LIMITS indicates that the
- * signed max_grant_frames and max_maptrack_frames fields in
- * libxl_domain_build_info are signed quantities.
+ * LIBXL_HAVE_BUILDINFO_GRANT_DEFAULT indicates that the default
+ * values of max_grant_frames and max_maptrack_frames fields in
+ * libxl_domain_build_info are the special sentinel value
+ * LIBXL_MAX_GRANT_DEFAULT rather than the fixed values above.
+ * This means to use the hypervisor's default.
  */
-#define LIBXL_HAVE_BUILDINFO_SIGNED_GRANT_LIMITS 1
-
-#define LIBXL_MAX_GRANT_FRAMES_DEFAULT -1
-#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT -1
+#define LIBXL_HAVE_BUILDINFO_GRANT_DEFAULT 1
 
 /*
  * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
tools/libxl/libxl_types.idl +2 -2
index 63e29bb2fb..7921950f6a 100644
@@ -511,8 +511,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")),
 
-    ("max_grant_frames",    integer, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
-    ("max_maptrack_frames", integer, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),
+    ("max_grant_frames",    uint32, {'init_val': 'LIBXL_MAX_GRANT_DEFAULT'}),
+    ("max_maptrack_frames", uint32, {'init_val': 'LIBXL_MAX_GRANT_DEFAULT'}),
     
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", libxl_defbool),
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#16 lore raw
In reply to Paul Durrant
Quoted 20 lines · Paul Durrant
tools/libxl/libxl.h +2 -2
index 49b56fa1a3..a2a5d321c5 100644
@@ -364,8 +364,8 @@
  */
 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
 
-#define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32
-#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024
+#define LIBXL_MAX_GRANT_FRAMES_DEFAULT -1
+#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT -1
 
 /*
  * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
tools/libxl/libxl_types.idl +0 -0
index 0546d7865a..63e29bb2fb 100644

tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[ · line 515

Quoted 7 lines
tools/libxl/libxl_types.idl +2 -2
@@ -511,8 +511,8 @@ libxl_domain_build_info = Struct("domain_build_info",[
 
     ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")),
 
-    ("max_grant_frames",    uint32, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
-    ("max_maptrack_frames", uint32, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),
+    ("max_grant_frames",    integer, {'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),
+    ("max_maptrack_frames", integer, {'init_val': 'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),

That's a change in the libxl API, could you add a LIBX_HAVE_* macro?

Quoted 27 lines
tools/libxl/libxl_types.idl +0 -0
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", libxl_defbool),
tools/libxl/libxlu_cfg.c +7 -2
index 72815d25dd..cafc632fc1 100644
@@ -268,8 +268,9 @@ int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n,
     return 0;
 }
 
-int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
-                     long *value_r, int dont_warn) {
+int xlu_cfg_get_bounded_long(const XLU_Config *cfg, const char *n,
+                             long min, long max, long *value_r,
+                             int dont_warn) {
     long l;
     XLU_ConfigSetting *set;
     int e;
@@ -303,10 +304,31 @@ int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
                     cfg->config_source, set->lineno, n);
         return EINVAL;
     }
+    if (l < min) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is smaller than minimum bound '%ld'\n",

tools/libxl/libxlu_cfg.c int xlu_cfg_get_long(const XLU_Config *cfg, const char *n, · line 320

Quoted 10 lines
tools/libxl/libxlu_cfg.c +10 -0
+                    cfg->config_source, set->lineno, l, min);
+        return EINVAL;
+    }
+    if (l > max) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is greater than maximum bound '%ld'\n",
+                    cfg->config_source, set->lineno, l, max);
+        return EINVAL;
+    }

I'm not sure what was the intention with the new function xlu_cfg_get_bounded_long(), but I don't think libxlu is the right place for it. That function is only going to make it harder for users to find mistakes in the config file. If `n' value is out of bound, it will only get ignored, and xl will keep going. I think xlu_cfg should only be a parser (and can check for syntax error).

Can you move that function to xl?

Thanks,

Signature · 6 lines
Anthony PERARD

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

-----Original Message-----
From: Anthony PERARD <[email protected]>
Sent: 29 November 2019 12:46
To: Durrant, Paul <[email protected]>
Cc: [email protected]; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Volodymyr Babchuk <[email protected]>; Roger Pau Monné <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

tools/libxl/libxl_types.idl libxl_domain_build_info =

Quoted 20 lines · Paul Durrant
tools/libxl/libxl.h +2 -2
index 49b56fa1a3..a2a5d321c5 100644
@@ -364,8 +364,8 @@
  */
 #define LIBXL_HAVE_BUILDINFO_GRANT_LIMITS 1
 
-#define LIBXL_MAX_GRANT_FRAMES_DEFAULT 32
-#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT 1024
+#define LIBXL_MAX_GRANT_FRAMES_DEFAULT -1
+#define LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT -1
 
 /*
  * LIBXL_HAVE_BUILDINFO_* indicates that libxl_domain_build_info has
tools/libxl/libxl_types.idl +0 -0
index 0546d7865a..63e29bb2fb 100644
@@ -511,8 +511,8 @@ libxl_domain_build_info =

Struct("domain_build_info",[

tools/libxl/libxl_types.idl libxl_domain_build_info = Struct("domain_build_info",[

Quoted 4 lines
tools/libxl/libxl_types.idl +0 -1
     ("vnuma_nodes", Array(libxl_vnode_info, "num_vnuma_nodes")),
 
-    ("max_grant_frames",    uint32, {'init_val':

'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),

Quoted 9 lines

tools/libxl/libxl_types.idl libxl_domain_build_info = · line 514

Quoted 1 line
tools/libxl/libxl_types.idl +0 -1
-    ("max_maptrack_frames", uint32, {'init_val':

'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),

tools/libxl/libxl_types.idl libxl_domain_build_info = · line 513

Quoted 1 line
tools/libxl/libxl_types.idl +1 -0
+    ("max_grant_frames",    integer, {'init_val':

'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),

tools/libxl/libxl_types.idl libxl_domain_build_info = · line 514

Quoted 1 line
tools/libxl/libxl_types.idl +1 -0
+    ("max_maptrack_frames", integer, {'init_val':

'LIBXL_MAX_MAPTRACK_FRAMES_DEFAULT'}),

That's a change in the libxl API, could you add a LIBX_HAVE_* macro?

Is it really, in practice?

Quoted 42 lines

tools/libxl/libxlu_cfg.c int xlu_cfg_replace_string(const XLU_Config *cfg,

Quoted 8 lines
tools/libxl/libxl_types.idl +0 -0
     ("device_model_version", libxl_device_model_version),
     ("device_model_stubdomain", libxl_defbool),
tools/libxl/libxlu_cfg.c +0 -0
index 72815d25dd..cafc632fc1 100644
@@ -268,8 +268,9 @@ int xlu_cfg_replace_string(const XLU_Config *cfg,

const char *n,

tools/libxl/libxlu_cfg.c int xlu_cfg_get_long(const XLU_Config *cfg, const

Quoted 12 lines
tools/libxl/libxlu_cfg.c +3 -2
     return 0;
 }
 
-int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,
-                     long *value_r, int dont_warn) {
+int xlu_cfg_get_bounded_long(const XLU_Config *cfg, const char *n,
+                             long min, long max, long *value_r,
+                             int dont_warn) {
     long l;
     XLU_ConfigSetting *set;
     int e;
@@ -303,10 +304,31 @@ int xlu_cfg_get_long(const XLU_Config *cfg, const

char *n,

tools/libxl/libxlu_cfg.c int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,

Quoted 7 lines
tools/libxl/libxlu_cfg.c +4 -0
                     cfg->config_source, set->lineno, n);
         return EINVAL;
     }
+    if (l < min) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is smaller than

minimum bound '%ld'\n",

tools/libxl/libxlu_cfg.c int xlu_cfg_get_long(const XLU_Config *cfg, const char *n,

Quoted 7 lines
tools/libxl/libxlu_cfg.c +7 -0
+                    cfg->config_source, set->lineno, l, min);
+        return EINVAL;
+    }
+    if (l > max) {
+        if (!dont_warn)
+            fprintf(cfg->report,
+                    "%s:%d: warning: value `%ld' is greater than

maximum bound '%ld'\n",

tools/libxl/libxlu_cfg.c int xlu_cfg_get_long(const XLU_Config *cfg, const char *n, · line 320

Quoted 3 lines
tools/libxl/libxlu_cfg.c +3 -0
+                    cfg->config_source, set->lineno, l, max);
+        return EINVAL;
+    }
Quoted 9 lines

I'm not sure what was the intention with the new function xlu_cfg_get_bounded_long(), but I don't think libxlu is the right place for it. That function is only going to make it harder for users to find mistakes in the config file. If `n' value is out of bound, it will only get ignored, and xl will keep going. I think xlu_cfg should only be a parser (and can check for syntax error).

Can you move that function to xl?

I can, but why is this not considered useful in libxl? The call returns failure for an out-of-bounds check. If xl currently chooses to treat EINVAL as ENOENT then that's xl's bug to deal with.

Paul

Quoted 4 lines

Thanks,

--
Anthony PERARD

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

#18 lore raw
Quoted 10 lines · Paul
Quoted 10 lines

-----Original Message-----
From: Anthony PERARD <[email protected]>
Sent: 29 November 2019 12:46
I'm not sure what was the intention with the new function xlu_cfg_get_bounded_long(), but I don't think libxlu is the right place for it. That function is only going to make it harder for users to find mistakes in the config file. If `n' value is out of bound, it will only get ignored, and xl will keep going. I think xlu_cfg should only be a parser (and can check for syntax error).

Quoted 4 lines
Quoted 2 lines

Can you move that function to xl?

I can, but why is this not considered useful in libxl? The call returns failure for an out-of-bounds check.

Sorry that the repo layout is confusing, but libxl != libxlu. libxl doesn't even use libxlu!

Quoted 1 line

If xl currently chooses to treat EINVAL as ENOENT then that's xl's bug to deal with.

The general use of xlu_cfg_get_*() that treats all errors as ENOENT in xl is an issue, I think, but this patch does the same thing and treat EINVAL as ENOENT when using the newly introduced xlu_cfg_get_bounded_long() function. I don't think that an xl bug to deal with, but an issue with the patch.

Cheers,

Signature · 6 lines
Anthony PERARD

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

-----Original Message-----
From: Anthony PERARD <[email protected]>
Sent: 29 November 2019 13:52
To: Durrant, Paul <[email protected]>
Cc: [email protected]; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Marek Marczykowski-Górecki <[email protected]>; Volodymyr Babchuk <[email protected]>; Roger Pau Monné <[email protected]>
Subject: Re: [PATCH-for-4.13 v5] Rationalize max_grant_frames and max_maptrack_frames handling

Quoted 5 lines · Paul
Quoted 5 lines

-----Original Message-----
From: Anthony PERARD <[email protected]>
Sent: 29 November 2019 12:46
I'm not sure what was the intention with the new function xlu_cfg_get_bounded_long(), but I don't think libxlu is the right

place

Quoted 1 line
Quoted 1 line

for it. That function is only going to make it harder for users to

find

Quoted 1 line
Quoted 1 line

mistakes in the config file. If `n' value is out of bound, it will

only

Quoted 3 lines
Quoted 3 lines

get ignored, and xl will keep going. I think xlu_cfg should only be a parser (and can check for syntax error).

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Can you move that function to xl?

I can, but why is this not considered useful in libxl? The call returns

failure for an out-of-bounds check.

Sorry that the repo layout is confusing, but libxl != libxlu. libxl doesn't even use libxlu!

Oh, that is confusing... there is code under tools/libxl that is not use by libxl; totally sane, of course.

Quoted 10 lines
Quoted 2 lines

If xl currently chooses to treat EINVAL as ENOENT then that's xl's bug

to deal with.

The general use of xlu_cfg_get_*() that treats all errors as ENOENT in xl is an issue, I think, but this patch does the same thing and treat EINVAL as ENOENT when using the newly introduced xlu_cfg_get_bounded_long() function. I don't think that an xl bug to deal with, but an issue with the patch.

True, but I don't think that makes things strictly worse. I'll send v6 with extra checks though.

Paul

Quoted 4 lines

Cheers,

--
Anthony PERARD

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