libxl/x86: check return value of SHADOW_OP_SET_ALLOCATION domctl
PATCH 1/1 libxl/x86: check return value of SHADOW_OP_SET_ALLOCATION domctl
The hypervisor may not have enough memory to satisfy the request.
---
Especially if the request was mostly fulfilled, guests may have done fine despite the failure, so there is a risk of perceived regressions here. But not checking the error at all was certainly wrong.
tools/libs/light/libxl_x86.c +12 -2
@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); +int rc =xc_shadow_control (ctx->xch, domid, +XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , +NULL ,0 , &shadow,0 ,NULL ); + +if (rc) { +LOGED (ERROR , domid, +"Failed to set %s allocation: %d (errno:%d)\n" , +libxl_defbool_val (d_config->c_info.hap) ?"HAP" :"shadow" , + rc, errno); + ret =ERROR_FAIL ; + goto out; + } } if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&
Quoted 15 lines · Jan Beulich
The hypervisor may not have enough memory to satisfy the request.
Requested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
Especially if the request was mostly fulfilled, guests may have done fine despite the failure, so there is a risk of perceived regressions here. But not checking the error at all was certainly wrong.tools/libs/light/libxl_x86.c +0
-0@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 );
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 541
Quoted 10 lines
tools/libs/light/libxl_x86.c +8
-2-xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); +int rc =xc_shadow_control (ctx->xch, domid, +XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , +NULL ,0 , &shadow,0 ,NULL ); + +if (rc) { + LOGED(ERROR, domid, + "Failed to set %s allocation: %d (errno:%d)\n", + libxl_defbool_val(d_config->c_info.hap) ? "HAP" : "shadow",
The error message wants to include the value of shadow, just in case the cause of the failure is because the value is stupidly high.
Having traced the number through, the local variable wants to be named shadow_mb to try and make the units clearer. (Also - why on earth do we have a hypercall which takes integer units of MB, and a memkb field in the config file...)
Otherwise, Reviewed-by: Andrew Cooper <[email protected]>
Quoted 12 lines · Jan Beulich
The hypervisor may not have enough memory to satisfy the request.
Requested-by Andrew Cooper <[email protected]>Signed-off-by Jan Beulich <[email protected]>---
Especially if the request was mostly fulfilled, guests may have done fine despite the failure, so there is a risk of perceived regressions here. But not checking the error at all was certainly wrong.
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 6 lines
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,
Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 538
Quoted 4 lines
tools/libs/light/libxl_x86.c +4
-0+XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , + NULL, 0, &shadow, 0, NULL); + +if (rc) {
xc_shadow_control seems to return "domctl.u.shadow_op.pages" in some cases, are all non-zero return value errors?
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 540
Quoted 2 lines
tools/libs/light/libxl_x86.c +2
-0+ LOGED(ERROR, domid, + "Failed to set %s allocation: %d (errno:%d)\n",
LOGED already prints prints the meaning of the "errno" value, so we don't need to log it.
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 542
Quoted 2 lines
tools/libs/light/libxl_x86.c +2
-0+libxl_defbool_val (d_config->c_info.hap) ?"HAP" :"shadow" , + rc, errno);
Is the return value of xc_shadow_control() actually useful when errno is already logged?
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 13 lines · Anthony PERARD
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 9 lines · Jan Beulich
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
Of course I can, but I did look at the rest of the function and found that it uses "ret" for the purpose of what you now say "rc" ought to be used for. Seeing "ret", I decided to avoid it (knowing you use different names for different kinds of return values). While I've switched to "r" for now, I'd be rather inclined to re-use "ret" instead. (Or actually, as per the remark further down, I can get away without any local variable then.)
Quoted 7 lines
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 538
Quoted 4 lines
tools/libs/light/libxl_x86.c +4
-0+XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , + NULL, 0, &shadow, 0, NULL); + +if (rc) {
xc_shadow_controlseems to return "domctl.u.shadow_op.pages" in some cases, are all non-zero return value errors?
Indeed it does, but (a) we pass in zero here and (b) this operation doesn't alter (nor even care about) the value. So I'd prefer to stick to what I have, but if you tell me to switch to "... < 0", I will.
Quoted 5 lines
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 540
Quoted 2 lines
tools/libs/light/libxl_x86.c +2
-0+ LOGED(ERROR, domid, + "Failed to set %s allocation: %d (errno:%d)\n",LOGED already prints prints the meaning of the "errno" value, so we don't need to log it.
I see. Please note that again I took neighboring code (a few lines down) for reference. Judging from other call sites (not the one right below here) I infer I also shouldn't have \n in the format string?
Quoted 5 lines
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 542
Quoted 2 lines
tools/libs/light/libxl_x86.c +2
-0+libxl_defbool_val (d_config->c_info.hap) ?"HAP" :"shadow" , + rc, errno);Is the return value of
xc_shadow_control()actually useful when errno is already logged?
I don't know. Again what I had matches what can be found a few lines down in the same function. But looking at other uses (in other files) I'm getting the impression that it's useless - dropped.
Jan
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Anthony PERARD
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 9 lines · Jan Beulich
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
Quoted 8 lines
Of course I can, but I did look at the rest of the function and found that it uses "ret" for the purpose of what you now say "rc" ought to be used for. Seeing "ret", I decided to avoid it (knowing you use different names for different kinds of return values). While I've switched to "r" for now, I'd be rather inclined to re-use "ret" instead. (Or actually, as per the remark further down, I can get away without any local variable then.)
I know there's quite a few (many?) coding style issue in libxl. I'm trying to prevent new issue without asking to fix the existing one. The use of "ret" is an already existing issue, so I'm fine with it been use in this patch for libxl error code in the function.
BTW, you still need to store the return value of xc_shadow_control() into a "r" variable before checking it for error.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
tools/libs/light/libxl_x86.c +4
-0+XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , + NULL, 0, &shadow, 0, NULL); + +if (rc) {
Quoted 7 lines
Quoted 2 lines
xc_shadow_controlseems to return "domctl.u.shadow_op.pages" in some cases, are all non-zero return value errors?Indeed it does, but (a) we pass in zero here and (b) this operation doesn't alter (nor even care about) the value. So I'd prefer to stick to what I have, but if you tell me to switch to "... < 0", I will.
That's fine, no need to change.
Quoted 11 lines
Quoted 6 lines
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 540
Quoted 3 lines
tools/libs/light/libxl_x86.c +2
-0+ LOGED(ERROR, domid, + "Failed to set %s allocation: %d (errno:%d)\n",LOGED already prints prints the meaning of the "errno" value, so we don't need to log it.
I see. Please note that again I took neighboring code (a few lines down) for reference. Judging from other call sites (not the one right below here) I infer I also shouldn't have \n in the format string?
Ah, indeed, the '\n' isn't needed.
Quoted 10 lines
Quoted 5 lines
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 542
Quoted 2 lines
tools/libs/light/libxl_x86.c +2
-0+libxl_defbool_val (d_config->c_info.hap) ?"HAP" :"shadow" , + rc, errno);Is the return value of
xc_shadow_control()actually useful when errno is already logged?I don't know. Again what I had matches what can be found a few lines down in the same function. But looking at other uses (in other files) I'm getting the impression that it's useless - dropped.
Whether or not the return value is useful to be logged depends only on xc_shadow_control(). But thanks.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 25 lines · Anthony PERARD
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Anthony PERARD
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 9 lines · Jan Beulich
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
Quoted 8 lines
Of course I can, but I did look at the rest of the function and found that it uses "ret" for the purpose of what you now say "rc" ought to be used for. Seeing "ret", I decided to avoid it (knowing you use different names for different kinds of return values). While I've switched to "r" for now, I'd be rather inclined to re-use "ret" instead. (Or actually, as per the remark further down, I can get away without any local variable then.)
Quoted 7 lines
I know there's quite a few (many?) coding style issue in libxl. I'm trying to prevent new issue without asking to fix the existing one. The use of "ret" is an already existing issue, so I'm fine with it been use in this patch for libxl error code in the function.
BTW, you still need to store the return value of
xc_shadow_control()into a "r" variable before checking it for error.
Are you saying that
if (xc_shadow_control(ctx->xch, domid,
XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION,
NULL, 0, &shadow_mb, 0, NULL)) {is not acceptable, style-wise? If indeed you are, please disambiguate your statement above regarding the use of "ret": May I or may I not use it? IOW do I need to introduce "r", or can I get away with the existing local variables.
Jan
Quoted 34 lines · Jan Beulich
Quoted 25 lines · Anthony PERARD
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Anthony PERARD
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 9 lines · Jan Beulich
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
Quoted 8 lines
Of course I can, but I did look at the rest of the function and found that it uses "ret" for the purpose of what you now say "rc" ought to be used for. Seeing "ret", I decided to avoid it (knowing you use different names for different kinds of return values). While I've switched to "r" for now, I'd be rather inclined to re-use "ret" instead. (Or actually, as per the remark further down, I can get away without any local variable then.)
Quoted 7 lines
I know there's quite a few (many?) coding style issue in libxl. I'm trying to prevent new issue without asking to fix the existing one. The use of "ret" is an already existing issue, so I'm fine with it been use in this patch for libxl error code in the function.
BTW, you still need to store the return value of
xc_shadow_control()into a "r" variable before checking it for error.
Quoted 7 lines
Are you saying that
if (xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow_mb, 0, NULL)) {is not acceptable, style-wise?
Oh, there is indeed such a rule under "ERROR HANDLING". Which means ...
Quoted 4 lines
If indeed you are, please disambiguate
your statement above regarding the use of "ret": May I or may I not use it? IOW do I need to introduce "r", or can I get away with the existing local variables.
... I need this to be clarified.
Jan
Quoted 43 lines · Jan Beulich
Quoted 34 lines · Jan Beulich
Quoted 25 lines · Anthony PERARD
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Anthony PERARD
tools/libs/light/libxl_x86.c int libxl__arch_domain_create(libxl__gc · line 534
Quoted 9 lines · Jan Beulich
tools/libs/light/libxl_x86.c +1
-2@@ -531,8 +531,18 @@ int libxl__arch_domain_create(libxl__gcif (d_config->b_info.type !=LIBXL_DOMAIN_TYPE_PV ) {unsigned long shadow =DIV_ROUNDUP (d_config->b_info.shadow_memkb,1024 ); -xc_shadow_control (ctx->xch, domid,XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION , -NULL ,0 , &shadow,0 ,NULL ); + int rc = xc_shadow_control(ctx->xch, domid,Could you use 'r' instead of 'rc' ? The later is reserved for libxl error codes while the former is for system and libxc calls.
Quoted 8 lines
Of course I can, but I did look at the rest of the function and found that it uses "ret" for the purpose of what you now say "rc" ought to be used for. Seeing "ret", I decided to avoid it (knowing you use different names for different kinds of return values). While I've switched to "r" for now, I'd be rather inclined to re-use "ret" instead. (Or actually, as per the remark further down, I can get away without any local variable then.)
Quoted 7 lines
I know there's quite a few (many?) coding style issue in libxl. I'm trying to prevent new issue without asking to fix the existing one. The use of "ret" is an already existing issue, so I'm fine with it been use in this patch for libxl error code in the function.
BTW, you still need to store the return value of
xc_shadow_control()into a "r" variable before checking it for error.Quoted 7 lines
Are you saying that
if (xc_shadow_control(ctx->xch, domid, XEN_DOMCTL_SHADOW_OP_SET_ALLOCATION, NULL, 0, &shadow_mb, 0, NULL)) {is not acceptable, style-wise?
Quoted 8 lines
Oh, there is indeed such a rule under "ERROR HANDLING". Which means ...
Quoted 4 lines
If indeed you are, please disambiguate
your statement above regarding the use of "ret": May I or may I not use it? IOW do I need to introduce "r", or can I get away with the existing local variables.... I need this to be clarified.
You need to introduce the "r" local variable, to store xc_shadow_control return value.
Then, set "ret" to ERROR_FAIL before "goto out;".
Hope that's clearer.
Cheers,
Signature · 1 line
Anthony PERARD