Support for reading hypervisor parameters at runtime
cover Support for reading hypervisor parameters at runtime
Currently parameters of the hypervisor cannot be inspected at runtime through an xl command. Such a command would be a useful diagnostic tool e.g. used in conjunction with the "xl set-parameters" command.
This patch series implements a new xl command "xl get-parameters" which takes a string of input parameters and returns their current values in the hypervisor settings.
Examples:
xl get-parameters "gnttab_max_frames gnttab_max_maptrack_frames" gnttab_max_frames gnttab_max_maptrack_frames : 64 1024
xl set-parameters gnttab_max_frames=128
xl get-parameters gnttab_max_framesgnttab_max_frames : 128
xl get-parameters "gnttab_max_frames gnttab_max_maptrack_frames" gnttab_max_frames gnttab_max_maptrack_frames : 128 1024
Vasilis Liaskovitis (4):
xen: add hypercall for getting parameters at runtime
libxc: add function to get hypervisor parameters
libxl: add libxl_get_parameters() function
xl: add new xl command set-parameters
docs/man/xl.1.pod.in | 5 ++ tools/flask/policy/modules/dom0.te | 2 +- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_misc.c | 26 +++++++ tools/libxl/libxl.c | 15 ++++ tools/libxl/libxl.h | 1 + tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 5 ++ tools/xl/xl_misc.c | 25 +++++++ xen/common/kernel.c | 109 ++++++++++++++++++++++++++++ xen/common/sysctl.c | 45 ++++++++++++ xen/include/public/sysctl.h | 18 +++++ xen/include/xen/lib.h | 1 + xen/xsm/flask/hooks.c | 3 + xen/xsm/flask/policy/access_vectors | 2 + 15 files changed, 258 insertions(+), 1 deletion(-)
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 1/4 xen: add hypercall for getting parameters at runtime
Add a sysctl hypercall to support getting hypervisor parameters at runtime.
--- tools/flask/policy/modules/dom0.te | 2 +- xen/common/kernel.c | 109 ++++++++++++++++++++++++++++ xen/common/sysctl.c | 45 ++++++++++++ xen/include/public/sysctl.h | 18 +++++ xen/include/xen/lib.h | 1 + xen/xsm/flask/hooks.c | 3 + xen/xsm/flask/policy/access_vectors | 2 + 7 files changed, 179 insertions(+), 1 deletion(-)
tools/flask/policy/modules/dom0.te +1 -1
@@ -16,7 +16,7 @@ allow dom0_t xen_t:xen { allow dom0_t xen_t:xen2 { resource_op psr_cmt_op psr_alloc pmu_ctrl get_symbol get_cpu_levelling_caps get_cpu_featureset livepatch_op - coverage_op set_parameter + coverage_op set_parameter get_parameter }; # Allow dom0 to use all XENVER_ subops that have checks.
xen/common/kernel.c +109 -0
121 lines not on this page · raw message
xen/common/sysctl.c +45 -0
51 lines not on this page · raw message
xen/include/public/sysctl.h +18 -0
@@ -1100,6 +1100,22 @@ typedef struct xen_sysctl_cpu_policy xen_sysctl_cpu_policy_t;DEFINE_XEN_GUEST_HANDLE (xen_sysctl_cpu_policy_t);#endif +/* +* XEN_SYSCTL_get_parameter +* +* Read hypervisor parameters at runtime. +* Parameters are a single string terminated by a NUL byte of max. size +* characters. Multiple settings can be specified by separating them +* with blanks. +*/ + +struct xen_sysctl_get_parameter { +XEN_GUEST_HANDLE_64 (char ) params;/* IN: pointer to parameters. */ +XEN_GUEST_HANDLE_64 (char ) values;/* OUT: pointer to output values. */ +uint16_t size;/* IN: size of parameters. */ +uint16_t pad[3 ];/* IN: MUST be zero. */ +}; +struct xen_sysctl {uint32_t cmd;#define XEN_SYSCTL_readconsole 1
@@ -1130,6 +1146,7 @@ struct xen_sysctl {#define XEN_SYSCTL_livepatch_op 27#define XEN_SYSCTL_set_parameter 28#define XEN_SYSCTL_get_cpu_policy 29 +#define XEN_SYSCTL_get_parameter 30uint32_t interface_version;/* XEN_SYSCTL_INTERFACE_VERSION */ union {struct xen_sysctl_readconsole readconsole;
@@ -1162,6 +1179,7 @@ struct xen_sysctl {#if defined(__i386__) || defined(__x86_64__)struct xen_sysctl_cpu_policy cpu_policy;#endif +struct xen_sysctl_get_parameter get_parameter;uint8_t pad[128 ]; } u; };
xen/include/xen/lib.h +1 -0
@@ -71,6 +71,7 @@ struct domain;void cmdline_parse (const char *cmdline);int runtime_parse (const char *line);int parse_bool (const char *s,const char *e); +int runtime_get_parameter (const char *line,char *values);/** * Given a specific name, parses a string of the form:
xen/xsm/flask/hooks.c +3 -0
@@ -830,6 +830,9 @@ static int flask_sysctl(int cmd)case XEN_SYSCTL_set_parameter:return avc_current_has_perm (SECINITSID_XEN ,SECCLASS_XEN2 ,XEN2__SET_PARAMETER ,NULL ); +case XEN_SYSCTL_get_parameter: +return avc_current_has_perm (SECINITSID_XEN ,SECCLASS_XEN2 , +XEN2__GET_PARAMETER ,NULL );default :return avc_unknown_permission ("sysctl" , cmd);
xen/xsm/flask/policy/access_vectors +2 -0
@@ -103,6 +103,8 @@ class xen2 coverage_op # XEN_SYSCTL_set_parameter set_parameter +# XEN_SYSCTL_get_parameter + get_parameter } # Classes domain and domain2 consist of operations that a domain performs on
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 83
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 06.03.19 at 13:58, <[email protected]> wrote:
xen/common/kernel.c +6
-0+static int get_params (const char *cmdline,char *values, +const struct kernel_param *start, +const struct kernel_param *end) +{ +char opt[128 ], *optkey, *q; +const char *p = cmdline, *val = values;
Why is val a pointer to const char? There are several casts below because of this, and all these casts should go away.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 96
Quoted 13 lines
xen/common/kernel.c +13
-0+const struct kernel_param *param; +int len, rc =0 ; +uint64_t param_int; +bool found; + +if (!values) +return -EFAULT ; + +for ( ; ; ) + { +/* Skip whitespace. */ +while ( *p ==' ' ) + p++;
For a user exposed interface I think it would be better to at least use isspace() here.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 104
Quoted 8 lines
xen/common/kernel.c +8
-0+if ( *p =='\0' ) +break ; + +/* Grab the next whitespace-delimited option. */ + q = optkey = opt; +while ( (*p !=' ' ) && (*p !='\0' ) ) + { +if ( (q-opt) < (sizeof (opt)-1 ) )/* avoid overflow */
Even if you copy existing code, please correct obvious style violations in the new instance - here there are blanks missing around binary operators.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 110
Quoted 6 lines
xen/common/kernel.c +6
-0+ *q++ = *p; + p++; + } + *q ='\0' ; + +/* Boolean parameters can be inverted with 'no-' prefix. */
This is an inapplicable comment in this function.
Quoted 1 line
+ found = false;
I don't think you need this variable here, or if so, it shouldn't be boolean: Either you mean to support returning data for multiple matching options (there are no runtime ones at present, but we at least used to have multiple-instance boot time ones), in which case you may need to invent a means to disambiguate them. Or you don't, in which case you could bail from the loop once you've found a match.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 123
Quoted 11 lines
xen/common/kernel.c +11
-0+for ( param = start; param < end; param++ ) + { + +if (strcmp (param->name, optkey) ) +continue ; + + found = true; +switch ( param->type ) + { +case OPT_STR : + len = snprintf((char*)val, sizeof(values), "%s ",
Here and below, sizeof(values) is wrong in two ways: For one it's sizeof(char*), not sizeof(char[nn]). And then you need to subtract the amount of space consumed already.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 129
Quoted 6 lines
xen/common/kernel.c +6
-0+ (char*)param->par.var); + val += len; +break ; +case OPT_UINT : +get_integer_param (param, ¶m_int); + len =snprintf ((char *)val,sizeof (values),"%lu " , param_int);
This is going to fail to build on 32-bit Arm. I'm also unconvinced this is appropriate if the value is actually a signed quantity.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 134
Quoted 5 lines
xen/common/kernel.c +5
-0+ val += len; +break ; +case OPT_BOOL : +get_integer_param (param, ¶m_int); + len = snprintf((char*)val, sizeof(values), "%s",
Above you add trailing blanks - why not here?
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 141
Quoted 7 lines
xen/common/kernel.c +7
-0+ param_int ? "true" : "false"); + val += len; +break ; +case OPT_SIZE : +case OPT_CUSTOM : + rc = -EINVAL ; +break ;
I can see why custom parameters can't be dealt with yet, but why also size ones? As to custom ones - four out of the seven runtime parameters we currently have are custom ones, so this limits the utility of the change quite a bit.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 150
Quoted 9 lines
xen/common/kernel.c +9
-0+default : +BUG (); +break ; + } + } + +if ( !found ) + { +printk ("get-parameters: parameter \"%s\" unknown!\n" , optkey);
I don't think logging of a message is appropriate here.
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 154
Quoted 4 lines
xen/common/kernel.c +4
-0+ rc = -EINVAL ; + } + } + *val ='\0' ;
Blank line above this one please. But does this even build, with val being pointer to const char?
xen/common/kernel.c int runtime_parse(const char *line) · line 309
Quoted 8 lines
xen/common/kernel.c +4
-0@@ -199,6 +303,11 @@ int runtime_parse(const char *line)return parse_params (line, __param_start, __param_end); } +int runtime_get_parameter (const char *line,char *values) +{ +return get_params (line, values, __param_start, __param_end); +}
I don't see the need for this wrapper.
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 506
Quoted 9 lines
xen/common/sysctl.c +3
-0@@ -501,6 +501,51 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)break ; } +case XEN_SYSCTL_get_parameter: + { +#define XEN_GET_PARAMETER_MAX_SIZE 1023
May I suggest to re-use XEN_SET_PARAMETER_MAX_SIZE, perhaps after renaming to XEN_PARAMETER_MAX_SIZE?
Quoted 11 lines
xen/common/sysctl.c +11
-0+char *params; +char *values; + +if ( op->u.get_parameter.pad[0 ] || op->u.get_parameter.pad[1 ] || + op->u.get_parameter.pad[2 ] ) + { + ret = -EINVAL ; +break ; + } +if ( op->u.get_parameter.size >XEN_GET_PARAMETER_MAX_SIZE ) + {
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 527
Quoted 10 lines
xen/common/sysctl.c +10
-0+ ret = -E2BIG ; +break ; + } + params =xmalloc_bytes (op->u.get_parameter.size +1 ); + values =xmalloc_bytes (XEN_GET_PARAMETER_MAX_SIZE ); +if ( !params ) + { + ret = -ENOMEM ; +break ; + }
What if params is non-NULL, but values is NULL? Also here and in one instance below you leak memory on the error paths.
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 533
Quoted 6 lines
xen/common/sysctl.c +6
-0+if (copy_from_guest (params, op->u.get_parameter.params, + op->u.get_parameter.size) ) + ret = -EFAULT ; +else + { + params[op->u.get_parameter.size] =0 ;
Even if this is a sysctl, please use array_access_nospec() here.
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 537
Quoted 4 lines
xen/common/sysctl.c +4
-0+ ret =runtime_get (params, values); + +if (copy_to_guest (op->u.get_parameter.values, values, +strlen (values)) )
You should only copy when ret is zero.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
thanks for the review.
Quoted 10 lines · Jan Beulich
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 83
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 06.03.19 at 13:58, <[email protected]> wrote:
xen/common/kernel.c +6
-0+static int get_params (const char *cmdline,char *values, +const struct kernel_param *start, +const struct kernel_param *end) +{ +char opt[128 ], *optkey, *q; +const char *p = cmdline, *val = values;Why is val a pointer to const char? There are several casts below because of this, and all these casts should go away.
yes, it should be a pointer to char, and those casts are not needed, I sent out an older version by mistake.
Quoted 17 lines
Quoted 4 lines
xen/common/kernel.c +3
-0+const struct kernel_param *param; +int len, rc =0 ; +uint64_t param_int;xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 96
Quoted 10 lines
xen/common/kernel.c +10
-0+bool found; + +if (!values) +return -EFAULT ; + +for ( ; ; ) + { +/* Skip whitespace. */ +while ( *p ==' ' ) + p++;For a user exposed interface I think it would be better to at least use
isspace()here.
ok
Quoted 10 lines
Quoted 2 lines
+ found = false;
I don't think you need this variable here, or if so, it shouldn't be boolean: Either you mean to support returning data for multiple matching options (there are no runtime ones at present, but we at least used to have multiple-instance boot time ones), in which case you may need to invent a means to disambiguate them. Or you don't, in which case you could bail from the loop once you've found a match.
Multiple matching options was not my intention. Yes, the loop going through the parameters should be exited on a match, but I still need to detect if there was no parameter matched at all for the current option, in order to return -EINVAL in that case. This can be detected from the return value of strcmp, instead of using a boolean variable.
Quoted 16 lines
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 123
Quoted 12 lines
xen/common/kernel.c +11
-0+for ( param = start; param < end; param++ ) + { + +if (strcmp (param->name, optkey) ) +continue ; + + found = true; +switch ( param->type ) + { +case OPT_STR : + len = snprintf((char*)val, sizeof(values), "%s ",Here and below, sizeof(values) is wrong in two ways: For one it's
sizeof(char*), notsizeof(char[nn]). And then you need to subtract the amount of space consumed already.
thanks, a basic mistake. I think the caller will need to pass the size of the values[] buffer as an argument to the function, or I can always assume a XEN_PARAMETER_SIZE max size for the values[] buffer. The former sounds better to me.
Quoted 10 lines
Quoted 8 lines
xen/common/kernel.c +6
-0+ (char*)param->par.var); + val += len; +break ; +case OPT_UINT : +get_integer_param (param, ¶m_int); + len = snprintf((char*)val, sizeof(values), "%lu ",
param_int);This is going to fail to build on 32-bit Arm.
I will change the formatting to %"PRIu64"
Quoted 3 lines
I'm also
unconvinced this is appropriate if the value is actually a signed quantity.
isn't OPT_UINT only for unsigned integers?
Quoted 10 lines
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 141
Quoted 9 lines
xen/common/kernel.c +7
-0+ param_int ? "true" : "false"); + val += len; +break ; +case OPT_SIZE : +case OPT_CUSTOM : + rc = -EINVAL ; +break ;
Quoted 4 lines
I can see why custom parameters can't be dealt with yet, but why also size ones? As to custom ones - four out of the seven runtime parameters we currently have are custom ones, so this limits the utility of the change quite a bit.
From what I understand OPT_SIZE can be handled similarly to OPT_UINT, printing an unsigned integer in the output.
For OPT_CUSTOM, what about adding a get_func function pointer to their definition in kernel_param, which would be used for reading the current value? So the union par of struct kernel_param would now have a struct with 2 function pointers for the custom parameters, something like:
union {
void *var;
struct {
int (*func)(const char *);
const char *(*get_func)(void);
} custom;
} par;with the new get_func prototype being:
const char *(*get_func)(void);
returning a string with the current value of the parameter.
e.g. the function for loglvl, guest_loglvl could return output using loglvl_str() : "Nothing", "Errors", "Errors and warnings" etc.
An alternative prototype could be:
int (*get_func)(char *output);
if we want the function to write the current parameter value into a caller-provided buffer, and possibly return error codes. The first option looks simpler to me.
The new custom function would have to be implemented of course for the 4 existing and any future custom parameters.
Quoted 12 lines
Quoted 11 lines
xen/common/kernel.c +9
-0+default : +BUG (); +break ; + } + } + +if ( !found ) + { + printk("get-parameters: parameter \"%s\" unknown!\n",optkey);
Quoted 1 line
I don't think logging of a message is appropriate here.
ok
Quoted 11 lines
xen/common/kernel.c int runtime_parse(const char *line) · line 309
Quoted 9 lines
xen/common/kernel.c +4
-0@@ -199,6 +303,11 @@ int runtime_parse(const char *line)return parse_params (line, __param_start, __param_end); } +int runtime_get_parameter (const char *line,char *values) +{ +return get_params (line, values, __param_start, __param_end); +}I don't see the need for this wrapper.
I think I had trouble accessing __param_start, __param_end directly from do_sysctl in xen/common/sysctl.c , that's why this was needed. But perhaps I missed something obvious.
Quoted 6 lines
Quoted 6 lines
xen/common/sysctl.c +0
-0@@ -501,6 +501,51 @@ longdo_sysctl (XEN_GUEST_HANDLE_PARAM (xen_sysctl_t ) u_sysctl)
Quoted 8 lines
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 506
Quoted 5 lines
xen/common/sysctl.c +3
-0break ; } +case XEN_SYSCTL_get_parameter: + { +#define XEN_GET_PARAMETER_MAX_SIZE 1023May I suggest to re-use
XEN_SET_PARAMETER_MAX_SIZE, perhaps after renaming toXEN_PARAMETER_MAX_SIZE?
ok
Quoted 25 lines
Quoted 14 lines
xen/common/sysctl.c +4
-0+char *params; +char *values; + + if ( op->u.get_parameter.pad[0] || op-Quoted 1 line
u.get_parameter.pad[1] ||
xen/common/sysctl.c +6
-0+ op->u.get_parameter.pad[2] ) + { + ret = -EINVAL ; +break ; + } + if ( op->u.get_parameter.size > XEN_GET_PARAMETER_MAX_SIZE)
xen/common/sysctl.c +1
-0+ {xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 527
Quoted 10 lines
xen/common/sysctl.c +10
-0+ ret = -E2BIG ; +break ; + } + params =xmalloc_bytes (op->u.get_parameter.size +1 ); + values =xmalloc_bytes (XEN_GET_PARAMETER_MAX_SIZE ); +if ( !params ) + { + ret = -ENOMEM ; +break ; + }
Quoted 2 lines
What if params is non-NULL, but values is NULL? Also here and in one instance below you leak memory on the error paths.
I 'll fix these, thanks.
Quoted 9 lines
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 533
Quoted 7 lines
xen/common/sysctl.c +6
-0+if (copy_from_guest (params, op->u.get_parameter.params, + op->u.get_parameter.size) ) + ret = -EFAULT ; +else + { + params[op->u.get_parameter.size] =0 ;Even if this is a sysctl, please use
array_access_nospec()here.
ok
Quoted 7 lines
xen/common/sysctl.c long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) · line 537
Quoted 5 lines
xen/common/sysctl.c +4
-0+ ret =runtime_get (params, values); + +if (copy_to_guest (op->u.get_parameter.values, values, +strlen (values)) )You should only copy when ret is zero.
right, thanks.
I 'll send a v2 after a few points above are cleared further.
thanks,
- Vasilis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 14:34, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 06.03.19 at 13:58, <[email protected]> wrote:
+ found = false;
I don't think you need this variable here, or if so, it shouldn't be boolean: Either you mean to support returning data for multiple matching options (there are no runtime ones at present, but we at least used to have multiple-instance boot time ones), in which case you may need to invent a means to disambiguate them. Or you don't, in which case you could bail from the loop once you've found a match.
Quoted 5 lines
Multiple matching options was not my intention. Yes, the loop going through the parameters should be exited on a match, but I still need to detect if there was no parameter matched at all for the current option, in order to return
-EINVALin that case. This can be detected from the return value of strcmp, instead of using a boolean variable.
From the return value of strcmp()? I don't think so, because you may have run past all table entries. Instead it's that property that you can use, i.e. checking whether ...
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ for ( param = start; param < end; param++ )
... the loop end condition was hit.
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/common/kernel.c +6
-0+ { + +if (strcmp (param->name, optkey) ) +continue ; + + found = true;Quoted 8 lines
xen/common/kernel.c static int assign_integer_param(const struct kernel_param *param, uint64_t val) · line 123
Quoted 4 lines
xen/common/kernel.c +4
-0+switch ( param->type ) + { +case OPT_STR : + len = snprintf((char*)val, sizeof(values), "%s ",Here and below, sizeof(values) is wrong in two ways: For one it's
sizeof(char*), notsizeof(char[nn]). And then you need to subtract the amount of space consumed already.
Quoted 4 lines
thanks, a basic mistake. I think the caller will need to pass the size of the values[] buffer as an argument to the function, or I can always assume a
XEN_PARAMETER_SIZEmax size for the values[] buffer. The former sounds better to me.
Indeed.
Quoted 10 lines
Quoted 9 lines
Quoted 7 lines
xen/common/kernel.c +6
-0+ (char*)param->par.var); + val += len; +break ; +case OPT_UINT : +get_integer_param (param, ¶m_int); + len = snprintf((char*)val, sizeof(values), "%lu ",
param_int);This is going to fail to build on 32-bit Arm.
Quoted 8 lines
I will change the formatting to %"PRIu64"
Quoted 3 lines
I'm also
unconvinced this is appropriate if the value is actually a signed quantity.isn't
OPT_UINTonly for unsigned integers?
You'll notice that there's no OPT_INT or OPT_SINT. OPT_UINT may be slightly misleading as a name. Otoh we probably don't have very many signed integer options.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
xen/common/kernel.c +7
-0+ param_int ? "true" : "false"); + val += len; +break ; +case OPT_SIZE : +case OPT_CUSTOM : + rc = -EINVAL ; +break ;
Quoted 7 lines
Quoted 4 lines
I can see why custom parameters can't be dealt with yet, but why also size ones? As to custom ones - four out of the seven runtime parameters we currently have are custom ones, so this limits the utility of the change quite a bit.
From what I understand
OPT_SIZEcan be handled similarly toOPT_UINT, printing an unsigned integer in the output.
Right.
Quoted 14 lines
For
OPT_CUSTOM, what about adding aget_funcfunction pointer to their definition inkernel_param, which would be used for reading the current value? So the union par of structkernel_paramwould now have a struct with 2 function pointers for the custom parameters, something like:union { void *var; struct { int (*func)(const char *); const char *(*get_func)(void); } custom; } par;
Quoted 5 lines
with the new
get_funcprototype being:const char *(*get_func)(void);returning a string with the current value of the parameter.
And where would the storage live for the string?
Quoted 9 lines
e.g. the function for loglvl,
guest_loglvlcould return output usingloglvl_str(): "Nothing", "Errors", "Errors and warnings" etc.An alternative prototype could be:
int (*get_func)(char *output);if we want the function to write the current parameter value into a caller-provided buffer, and possibly return error codes.
And how would the callee know how much space there is?
Quoted 1 line
The first option looks simpler to me.
Simpler is often, but not always better.
Quoted 11 lines
Quoted 10 lines
xen/common/kernel.c int runtime_parse(const char *line) · line 309
Quoted 8 lines
xen/common/kernel.c +4
-0@@ -199,6 +303,11 @@ int runtime_parse(const char *line)return parse_params (line, __param_start, __param_end); } +int runtime_get_parameter (const char *line,char *values) +{ +return get_params (line, values, __param_start, __param_end); +}I don't see the need for this wrapper.
Quoted 3 lines
I think I had trouble accessing
__param_start,__param_enddirectly fromdo_sysctlinxen/common/sysctl.c, that's why this was needed. But perhaps I missed something obvious.
You certainly shouldn't access them from sysctl.c. You should simply make get_params() access them instead of what its only caller passes, at which point the function should be renamed to it only caller's name.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 8 lines · Jan Beulich
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
From the return value of
strcmp()? I don't think so, because youmay have run past all table entries. Instead it's that property that you can use, i.e. checking whether ...
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ for ( param = start; param < end; param++ )
... the loop end condition was hit.
right.
Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
I'm also
unconvinced this is appropriate if the value is actually a signed quantity.isn't
OPT_UINTonly for unsigned integers?You'll notice that there's no
OPT_INTorOPT_SINT.OPT_UINTmay be slightly misleading as a name. Otoh we probably don't have very many signed integer options.
I see. Assuming an unsigned parameter is problematic then.
Doesn't the .data.param section (between __param_start and __param_end) only include runtime parameters, of which the integer ones are all unsigned integers at the moment? Or would you like to see this functionality eventually used for all parameters, including non-runtime as well?
Quoted 8 lines
Quoted 6 lines
with the new
get_funcprototype being:const char *(*get_func)(void);returning a string with the current value of the parameter.
And where would the storage live for the string?
I was thinking these custom functions would return static strings, as loglvl_str() does, and these would eventually be copied into the user provided values[] buffer via snprintf in get_params().
Quoted 5 lines
Quoted 5 lines
e.g. the function for loglvl,
guest_loglvlcould return output usingloglvl_str(): "Nothing", "Errors", "Errors and warnings" etc.
Quoted 8 lines
Quoted 6 lines
An alternative prototype could be:
int (*get_func)(char *output);if we want the function to write the current parameter value into a caller-provided buffer, and possibly return error codes.
And how would the callee know how much space there is?
yes, an extra size argument would be needed from the caller here.
Let me know if either of these or a different approach is preferred.
Quoted 5 lines
Quoted 1 line
You certainly shouldn't access them from
sysctl.c. You should simply makeget_params()access them instead of what its only caller passes, at which point the function should be renamed to it only caller's name.
... of course.
thanks,
- Vasilis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 16:44, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 3 lines
I'm also
unconvinced this is appropriate if the value is actually a signed quantity.isn't
OPT_UINTonly for unsigned integers?You'll notice that there's no
OPT_INTorOPT_SINT.OPT_UINTmay be slightly misleading as a name. Otoh we probably don't have very many signed integer options.
Quoted 7 lines
I see. Assuming an unsigned parameter is problematic then.
Doesn't the .data.param section (between
__param_startand__param_end) only include runtime parameters, of which the integer ones are all unsigned integers at the moment? Or would you like to see this functionality eventually used for all parameters, including non-runtime as well?
Well, at the very least I expect restrictions to be called out very clearly in the commit message. There not being any problematic runtime parameters right now doesn't mean some might not appear. And whether the problem would then be noticed is at least unpredictable. IOW not dealing with the case right away introduces a latent bug, and this shouldn't go unmentioned.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
with the new
get_funcprototype being:const char *(*get_func)(void);returning a string with the current value of the parameter.
And where would the storage live for the string?
I was thinking these custom functions would return static strings, as
loglvl_str()does, and these would eventually be copied into the user provided values[] buffer via snprintf inget_params().
Please don't limit your thinking to the few runtime parameters we currently have. At least to me it is quite obvious that there can easily be cases where static strings won't work.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
e.g. the function for loglvl,
guest_loglvlcould return output usingloglvl_str(): "Nothing", "Errors", "Errors and warnings" etc.An alternative prototype could be:
int (*get_func)(char *output);
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
if we want the function to write the current parameter value into a caller-provided buffer, and possibly return error codes.
And how would the callee know how much space there is?
yes, an extra size argument would be needed from the caller here.
Let me know if either of these or a different approach is preferred.
Of the two, I clearly prefer the latter. Then again me having pointed out the shortcoming doesn't mean we (and hence you for this patch) absolutely have to deal with custom parameters. Input from others would certainly be helpful here.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 56 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.03.19 at 16:44, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 3 lines
I'm also
unconvinced this is appropriate if the value is actually a signed quantity.isn't
OPT_UINTonly for unsigned integers?You'll notice that there's no
OPT_INTorOPT_SINT.OPT_UINTmay be slightly misleading as a name. Otoh we probably don't have very many signed integer options.Quoted 7 lines
I see. Assuming an unsigned parameter is problematic then.
Doesn't the .data.param section (between
__param_startand__param_end) only include runtime parameters, of which the integer ones are all unsigned integers at the moment? Or would you like to see this functionality eventually used for all parameters, including non-runtime as well?Well, at the very least I expect restrictions to be called out very clearly in the commit message. There not being any problematic runtime parameters right now doesn't mean some might not appear. And whether the problem would then be noticed is at least unpredictable. IOW not dealing with the case right away introduces a latent bug, and this shouldn't go unmentioned.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
with the new
get_funcprototype being:const char *(*get_func)(void);returning a string with the current value of the parameter.
And where would the storage live for the string?
I was thinking these custom functions would return static strings, as
loglvl_str()does, and these would eventually be copied into the user provided values[] buffer via snprintf inget_params().Please don't limit your thinking to the few runtime parameters we currently have. At least to me it is quite obvious that there can easily be cases where static strings won't work.
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
e.g. the function for loglvl,
guest_loglvlcould return output usingloglvl_str(): "Nothing", "Errors", "Errors and warnings" etc.An alternative prototype could be:
int (*get_func)(char *output);if we want the function to write the current parameter value into a caller-provided buffer, and possibly return error codes.
And how would the callee know how much space there is?
Quoted 8 lines
Quoted 3 lines
yes, an extra size argument would be needed from the caller here.
Let me know if either of these or a different approach is preferred.
Of the two, I clearly prefer the latter. Then again me having pointed out the shortcoming doesn't mean we (and hence you for this patch) absolutely have to deal with custom parameters. Input from others would certainly be helpful here.
Why don't we replace the "*get_func()" with a "char *current_val" being filled at parameter setting time? How current_val is allocated (static string or dynamic buffer) just has to be known by the custom parameter parsing function.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.03.19 at 07:07, <[email protected]> wrote:
Why don't we replace the "
*get_func()" with a "char*current_val" being filled at parameter setting time? Howcurrent_valis allocated (static string or dynamic buffer) just has to be known by the custom parameter parsing function.
Could accumulate (over time) to quite a bit of wasted allocations if no-one ever cares about calling the new sysctl.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 8 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.03.19 at 07:07, <[email protected]> wrote:
Why don't we replace the "
*get_func()" with a "char*current_val" being filled at parameter setting time? Howcurrent_valis allocated (static string or dynamic buffer) just has to be known by the custom parameter parsing function.Could accumulate (over time) to quite a bit of wasted allocations if no-one ever cares about calling the new sysctl.
In the normal case the needed memory shouldn't be more than that of the boot parameters, maybe plus some bytes in case runtime parameters are set. So I believe we are talking about less than one memory page.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 19.03.19 at 09:12, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 19.03.19 at 07:07, <[email protected]> wrote:
Why don't we replace the "
*get_func()" with a "char*current_val" being filled at parameter setting time? Howcurrent_valis allocated (static string or dynamic buffer) just has to be known by the custom parameter parsing function.
Quoted 6 lines
Quoted 2 lines
Could accumulate (over time) to quite a bit of wasted allocations if no-one ever cares about calling the new sysctl.
In the normal case the needed memory shouldn't be more than that of the boot parameters, maybe plus some bytes in case runtime parameters are set. So I believe we are talking about less than one memory page.
Total space needed may (for now) indeed not be very much, but setting this up would still be useless if the sysctl was never invoked, and prone to be forgotten to update when other parts of that command line option's handling get updated. I think there's less risk of returning stale data if the string gets re- constructed on demand.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Re: [PATCH v1 1/4] xen: add hypercall for getting parameters at runtime
In reply to a message not in the archiveQuoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
An alternative prototype could be:
int (*get_func)(char *output);if we want the function to write the current parameter value into a
caller-provided buffer, and possibly return error codes.And how would the callee know how much space there is?
Quoted 8 lines
Quoted 4 lines
yes, an extra size argument would be needed from the caller here.
Let me know if either of these or a different approach is preferred.
Of the two, I clearly prefer the latter. Then again me having pointed out the shortcoming doesn't mean we (and hence you for this patch) absolutely have to deal with custom parameters.
Unless there are objections, I think 'll send a v2 about getting non- custom parameter types first, and deal with custom parameters in a separate future patchset.
thanks,
- Vasilis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 2/4 libxc: add function to get hypervisor parameters
In reply to Vasilis LiaskovitisAdd a new libxc function to get hypervisor parameters at runtime.
--- tools/libxc/include/xenctrl.h | 1 + tools/libxc/xc_misc.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
tools/libxc/include/xenctrl.h +1 -0
@@ -1228,6 +1228,7 @@ int xc_readconsolering(xc_interface *xch,int xc_send_debug_keys (xc_interface *xch,char *keys);int xc_set_parameters (xc_interface *xch,char *params); +int xc_get_parameters (xc_interface *xch,char *params,char *values);typedef struct xen_sysctl_physinfo xc_physinfo_t ;typedef struct xen_sysctl_cputopo xc_cputopo_t ;
tools/libxc/xc_misc.c +26 -0
@@ -208,6 +208,32 @@ int xc_set_parameters(xc_interface *xch, char *params)return ret; } +int xc_get_parameters (xc_interface *xch,char *params,char *values) +{ +int ret, len =strlen (params); +DECLARE_SYSCTL ; +DECLARE_HYPERCALL_BOUNCE (params, len,XC_HYPERCALL_BUFFER_BOUNCE_IN ); +DECLARE_HYPERCALL_BOUNCE (values,1023 ,XC_HYPERCALL_BUFFER_BOUNCE_OUT ); + +if (xc_hypercall_bounce_pre (xch, params) ) +return -1 ; +if (xc_hypercall_bounce_pre (xch, values) ) +return -1 ; + + sysctl.cmd = XEN_SYSCTL_get_parameter; +set_xen_guest_handle (sysctl.u.get_parameter.params, params); +set_xen_guest_handle (sysctl.u.get_parameter.values, values); + sysctl.u.get_parameter.size = len; +memset (sysctl.u.get_parameter.pad,0 ,sizeof (sysctl.u.get_parameter.pad)); + + ret =do_sysctl (xch, &sysctl); + +xc_hypercall_bounce_post (xch, params); +xc_hypercall_bounce_post (xch, values); + +return ret; +} +int xc_physinfo (xc_interface *xch,xc_physinfo_t *put_info) {
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 3/4 libxl: add libxl_get_parameters() function
In reply to Vasilis LiaskovitisAdd a new libxl function to get hypervisor parameters at runtime.
--- tools/libxl/libxl.c | 15 +++++++++++++++ tools/libxl/libxl.h | 1 + 2 files changed, 16 insertions(+)
tools/libxl/libxl.c +15 -0
@@ -669,6 +669,21 @@ int libxl_set_parameters(libxl_ctx *ctx, char *params)return 0 ; } +int libxl_get_parameters (libxl_ctx *ctx,char *params,char *values) +{ +int ret; +GC_INIT (ctx); + + ret =xc_get_parameters (ctx->xch, params, values); +if (ret <0 ) { +LOGEV (ERROR , ret,"getting parameters" ); +GC_FREE ; +return ret;//ERROR_FAIL; + } +GC_FREE ; +return 0 ; +} +static int fd_set_flags (libxl_ctx *ctx,int fd,int fcntlgetop,int fcntlsetop,const char *fl,int flagmask,int set_p)
tools/libxl/libxl.h +1 -0
@@ -2307,6 +2307,7 @@ int libxl_send_trigger(libxl_ctx *ctx, uint32_t domid,int libxl_send_sysrq (libxl_ctx *ctx,uint32_t domid,char sysrq);int libxl_send_debug_keys (libxl_ctx *ctx,char *keys);int libxl_set_parameters (libxl_ctx *ctx,char *params); +int libxl_get_parameters (libxl_ctx *ctx,char *params,char *values);typedef struct libxl__xen_console_reader libxl_xen_console_reader ;
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
PATCH 4/4 xl: add new xl command get-parameters
In reply to Vasilis LiaskovitisAdd a new xl command "get-parameters" to get hypervisor parameters at runtime.
--- docs/man/xl.1.pod.in | 5 +++++ tools/xl/xl.h | 1 + tools/xl/xl_cmdtable.c | 5 +++++ tools/xl/xl_misc.c | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+)
docs/man/xl.1.pod.in +5 -0
@@ -827,6 +827,11 @@ Send debug I<keys> to Xen. It is the same as pressing the Xen Set hypervisor parameters as specified in I<params>. This allows for some boot parameters of the hypervisor to be modified in the running systems. +=item B<get-parameters> I<params> + +Get hypervisor parameters as specified in I<params>. This allows for some +boot parameters of the hypervisor to be read in the running systems. + =item B<dmesg> [I<OPTIONS>] Reads the Xen message buffer, similar to dmesg on a Linux system. The
tools/xl/xl.h +1 -0
@@ -219,6 +219,7 @@ int main_psr_mba_set(int argc, char **argv);int main_psr_mba_show (int argc,char **argv);#endif int main_qemu_monitor_command (int argc,char **argv); +int main_get_parameters (int argc,char **argv);void help (const char *command);
tools/xl/xl_cmdtable.c +5 -0
@@ -662,6 +662,11 @@ struct cmd_spec cmd_table[] = { "Issue a qemu monitor command to the device model of a domain", "<Domain> <Command>", }, + {"get-parameters" , + &main_get_parameters,0 ,1 , +"Get hypervisor parameters" , + "<Params>", + }, };int cmdtable_len =sizeof (cmd_table)/sizeof (struct cmd_spec );
tools/xl/xl_misc.c +25 -0
@@ -364,6 +364,31 @@ int main_config_update(int argc, char **argv)return 0 ; } +int main_get_parameters (int argc,char **argv) +{ +int opt, ret; +char *params; +char values[1023 ]; + + SWITCH_FOREACH_OPT(opt, "", NULL, "get-parameters", 1) { +/* No options */ + } + + params = argv[optind]; + +if (!params) { +fprintf (stderr,"no parameter specified\n" ); +return EXIT_FAILURE ; + } +else if ((ret =libxl_get_parameters (ctx, params, values))) { +fprintf (stderr,"cannot get parameters: %s : %d\n" , params, ret); +fprintf (stderr,"Use \"xl dmesg\" to look for possible reason.\n" ); +return EXIT_FAILURE ; + } +fprintf (stderr,"%s : %s\n" , params, values); + +return EXIT_SUCCESS ; +}/* * Local variables: * mode: C
Signature · 7 lines
2.20.1 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel