[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2] tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set


  • To: Wei Liu <wei.liu2@xxxxxxxxxx>
  • From: Juergen Gross <jgross@xxxxxxxx>
  • Date: Wed, 5 Sep 2018 14:14:46 +0200
  • Autocrypt: addr=jgross@xxxxxxxx; prefer-encrypt=mutual; keydata= xsBNBFOMcBYBCACgGjqjoGvbEouQZw/ToiBg9W98AlM2QHV+iNHsEs7kxWhKMjrioyspZKOB ycWxw3ie3j9uvg9EOB3aN4xiTv4qbnGiTr3oJhkB1gsb6ToJQZ8uxGq2kaV2KL9650I1SJve dYm8Of8Zd621lSmoKOwlNClALZNew72NjJLEzTalU1OdT7/i1TXkH09XSSI8mEQ/ouNcMvIJ NwQpd369y9bfIhWUiVXEK7MlRgUG6MvIj6Y3Am/BBLUVbDa4+gmzDC9ezlZkTZG2t14zWPvx XP3FAp2pkW0xqG7/377qptDmrk42GlSKN4z76ELnLxussxc7I2hx18NUcbP8+uty4bMxABEB AAHNHkp1ZXJnZW4gR3Jvc3MgPGpncm9zc0BzdXNlLmRlPsLAeQQTAQIAIwUCU4xw6wIbAwcL CQgHAwIBBhUIAgkKCwQWAgMBAh4BAheAAAoJELDendYovxMvi4UH/Ri+OXlObzqMANruTd4N zmVBAZgx1VW6jLc8JZjQuJPSsd/a+bNr3BZeLV6lu4Pf1Yl2Log129EX1KWYiFFvPbIiq5M5 kOXTO8Eas4CaScCvAZ9jCMQCgK3pFqYgirwTgfwnPtxFxO/F3ZcS8jovza5khkSKL9JGq8Nk czDTruQ/oy0WUHdUr9uwEfiD9yPFOGqp4S6cISuzBMvaAiC5YGdUGXuPZKXLpnGSjkZswUzY d9BVSitRL5ldsQCg6GhDoEAeIhUC4SQnT9SOWkoDOSFRXZ+7+WIBGLiWMd+yKDdRG5RyP/8f 3tgGiB6cyuYfPDRGsELGjUaTUq3H2xZgIPfOwE0EU4xwFgEIAMsx+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atgMZ2W0CFC4hJ3YEetuRBURYPiGzuJXU pAd7a7BdsqWC4o+GTm5tnGrCyD+4gfDSpkOT53S/GNO07YkPkm/8J4OBoFfgSaCnQ1izwgJQ jIpcG2fPCI2/hxf2oqXPYbKr1v4Z1wthmoyUgGN0LPTIm+B5vdY82wI5qe9uN6UOGyTH2B3p hRQUWqCwu2sqkI3LLbTdrnyDZaixT2T0f4tyF5Lfs+Ha8xVMhIyzNb1byDI5FKCb
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, ian.jackson@xxxxxxxxxxxxx
  • Delivery-date: Wed, 05 Sep 2018 12:15:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Openpgp: preference=signencrypt

On 05/09/18 12:55, Wei Liu wrote:
> On Wed, Sep 05, 2018 at 11:19:09AM +0100, Wei Liu wrote:
>> On Mon, Sep 03, 2018 at 02:59:42PM +0200, Juergen Gross wrote:
>>> Trying to set the number of vcpus of a domain to 0 isn't refused.
>>> We should not allow that.
>>>
>>> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
>>> ---
>>>  tools/libxl/libxl_domain.c | 6 ++++++
>>>  tools/xl/xl_vcpu.c         | 5 +++--
>>>  2 files changed, 9 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
>>> index 533bcdf240..3377bba994 100644
>>> --- a/tools/libxl/libxl_domain.c
>>> +++ b/tools/libxl/libxl_domain.c
>>> @@ -1369,6 +1369,12 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t 
>>> domid, libxl_bitmap *cpumap)
>>>      }
>>>  
>>>      maxcpus = libxl_bitmap_count_set(cpumap);
>>> +    if (maxcpus == 0)
>>> +    {
>>> +        LOGED(ERROR, domid, "Requested 0 VCPUs!");
>>> +        rc = ERROR_FAIL;
>>> +        goto out;
>>> +    }
>>>      if (maxcpus > info.vcpu_max_id + 1)
>>>      {
>>>          LOGED(ERROR, domid, "Requested %d VCPUs, however maxcpus is %d!",
>>> diff --git a/tools/xl/xl_vcpu.c b/tools/xl/xl_vcpu.c
>>> index aef486864c..3057c22aae 100644
>>> --- a/tools/xl/xl_vcpu.c
>>> +++ b/tools/xl/xl_vcpu.c
>>> @@ -331,13 +331,14 @@ int main_vcpupin(int argc, char **argv)
>>>  static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
>>>  {
>>>      char *endptr;
>>> -    unsigned int max_vcpus, i;
>>> +    unsigned int i;
>>> +    unsigned long max_vcpus;
>>>      libxl_bitmap cpumap;
>>>      int rc;
>>>  
>>>      libxl_bitmap_init(&cpumap);
>>>      max_vcpus = strtoul(nr_vcpus, &endptr, 10);
>>> -    if (nr_vcpus == endptr) {
>>> +    if (nr_vcpus == endptr || max_vcpus > INT_MAX) {
>>
>> e -I/build/tools/xl/../../tools/include -D__XEN_TOOLS__ 
>> -I/build/tools/xl/../../tools/include -Wshadow -include 
>> /build/tools/xl/../../tools/config.h   -c -o xl_cdrom.o xl_cdrom.c
>> xl_vcpu.c: In function 'vcpuset':
>> xl_vcpu.c:341:43: error: 'INT_MAX' undeclared (first use in this function)
>>      if (nr_vcpus == endptr || max_vcpus > INT_MAX) {
>>                                            ^~~~~~~
>> xl_vcpu.c:341:43: note: each undeclared identifier is reported only once for 
>> each function it appears in
>> xl_vcpu.c:361:29: error: format '%d' expects argument of type 'int', but 
>> argument 4 has type 'long unsigned int' [-Werror=format=]
>>              fprintf(stderr, "You are overcommmitting! You have %d physical" 
>> \
>>                              ^
>> xl_vcpu.c:379:74: error: format '%d' expects argument of type 'int', but 
>> argument 4 has type 'long unsigned int' [-Werror=format=]
>>          fprintf(stderr, "libxl_set_vcpuonline failed domid=%u 
>> max_vcpus=%d," \
>>
>>
>> Missing a header?
>>
> 
> Add limits.h and use %ld to print max_vcpus.

Yes. No idea why I didn't spot that.


Juergen

> 
> ---8<---
> From 2c0b1824b1cb33a2610f3f55299247f9e0464466 Mon Sep 17 00:00:00 2001
> From: Juergen Gross <jgross@xxxxxxxx>
> Date: Mon, 3 Sep 2018 14:59:42 +0200
> Subject: [PATCH] tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set
> 
> Trying to set the number of vcpus of a domain to 0 isn't refused.
> We should not allow that.
> 
> Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>
> Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
> ---
>  tools/libxl/libxl_domain.c |  6 ++++++
>  tools/xl/xl_vcpu.c         | 10 ++++++----
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
> index 533bcdf240..3377bba994 100644
> --- a/tools/libxl/libxl_domain.c
> +++ b/tools/libxl/libxl_domain.c
> @@ -1369,6 +1369,12 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t 
> domid, libxl_bitmap *cpumap)
>      }
>  
>      maxcpus = libxl_bitmap_count_set(cpumap);
> +    if (maxcpus == 0)
> +    {
> +        LOGED(ERROR, domid, "Requested 0 VCPUs!");
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
>      if (maxcpus > info.vcpu_max_id + 1)
>      {
>          LOGED(ERROR, domid, "Requested %d VCPUs, however maxcpus is %d!",
> diff --git a/tools/xl/xl_vcpu.c b/tools/xl/xl_vcpu.c
> index aef486864c..71d3a5c96d 100644
> --- a/tools/xl/xl_vcpu.c
> +++ b/tools/xl/xl_vcpu.c
> @@ -13,6 +13,7 @@
>   */
>  
>  #include <stdlib.h>
> +#include <limits.h>
>  
>  #include <libxl.h>
>  #include <libxl_utils.h>
> @@ -331,13 +332,14 @@ int main_vcpupin(int argc, char **argv)
>  static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
>  {
>      char *endptr;
> -    unsigned int max_vcpus, i;
> +    unsigned int i;
> +    unsigned long max_vcpus;
>      libxl_bitmap cpumap;
>      int rc;
>  
>      libxl_bitmap_init(&cpumap);
>      max_vcpus = strtoul(nr_vcpus, &endptr, 10);
> -    if (nr_vcpus == endptr) {
> +    if (nr_vcpus == endptr || max_vcpus > INT_MAX) {
>          fprintf(stderr, "Error: Invalid argument.\n");
>          return 1;
>      }
> @@ -358,7 +360,7 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, 
> int check_host)
>  
>          if (max_vcpus > online_vcpus && max_vcpus > host_cpu) {
>              fprintf(stderr, "You are overcommmitting! You have %d physical" \
> -                    " CPUs and want %d vCPUs! Aborting, use --ignore-host 
> to" \
> +                    " CPUs and want %ld vCPUs! Aborting, use --ignore-host 
> to" \
>                      " continue\n", host_cpu, max_vcpus);
>              return 1;
>          }
> @@ -375,7 +377,7 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, 
> int check_host)
>      if (rc == ERROR_DOMAIN_NOTFOUND)
>          fprintf(stderr, "Domain %u does not exist.\n", domid);
>      else if (rc)
> -        fprintf(stderr, "libxl_set_vcpuonline failed domid=%u max_vcpus=%d," 
> \
> +        fprintf(stderr, "libxl_set_vcpuonline failed domid=%u 
> max_vcpus=%ld," \
>                  " rc: %d\n", domid, max_vcpus, rc);
>  
>      libxl_bitmap_dispose(&cpumap);
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.