WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH] Qemu: Add sanity check for vcpu config

To: "Liu, Jinsong" <jinsong.liu@xxxxxxxxx>, xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH] Qemu: Add sanity check for vcpu config
From: Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Date: Sun, 21 Mar 2010 17:15:54 +0000
Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Delivery-date: Sun, 21 Mar 2010 10:16:48 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <EB8593BCECAB3D40A8248BE0B6400A3846520405@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcrJCH/DZwT17+XbQ1iHnLJTR2lfuQAEan6G
Thread-topic: [PATCH] Qemu: Add sanity check for vcpu config
User-agent: Microsoft-Entourage/12.23.0.091001
Wouldn't xend be a more sensible place to do the check? It can certainly
result in a better error message, I would have thought.

 -- Keir

On 21/03/2010 15:09, "Liu, Jinsong" <jinsong.liu@xxxxxxxxx> wrote:

> From 4d483620c863f626543fdc407c2951ceef49623e Mon Sep 17 00:00:00 2001
> From: Liu, Jinsong <jinsong.liu@xxxxxxxxx>
> Date: Sun, 21 Mar 2010 22:48:04 +0800
> Subject: [PATCH] Qemu: Add sanity check for vcpu config
> 
> Currently Xen/Qemu support max 128 vcpus. To avoid mis-setting
> at config file, this patch add sanity check for vcpu config.
> 1. maxvcpus and vcpus should no more than HVM_MAX_VCPUS (128)
> 2. vcpus should no more than maxvcpus.
> 
> Signed-off-by: Liu, Jinsong <jinsong.liu@xxxxxxxxx>
> ---
>  vl.c |   30 ++++++++++++++++++++++++++++++
>  1 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/vl.c b/vl.c
> index 30debd7..d69d90c 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -4706,6 +4706,34 @@ static void termsig_setup(void)
>  
>  #endif
>  
> +/* 32bit Hamming weight */
> +unsigned int hweight32(unsigned int w)
> +{
> + unsigned int res = w - ((w >> 1) & 0x55555555);
> + res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
> + res = (res + (res >> 4)) & 0x0F0F0F0F;
> + res = res + (res >> 8);
> + return (res + (res >> 16)) & 0x000000FF;
> +}
> +
> +static void vcpu_sanity_check(void)
> +{
> +    int i, vcpu_avail_weight = 0;
> +
> +    for (i=0; i<((HVM_MAX_VCPUS + 31)/32); i++)
> +        vcpu_avail_weight += hweight32(vcpu_avail[i]);
> +
> +    if (vcpus > HVM_MAX_VCPUS) {
> +        fprintf(stderr, "maxvcpus and vcpus should not more than %d\n",
> +                         HVM_MAX_VCPUS);
> +        exit(EXIT_FAILURE);
> +    }
> +    if (vcpu_avail_weight > vcpus) {
> +        fprintf(stderr, "vcpus should not more than maxvcpus\n");
> +        exit(EXIT_FAILURE);
> +    }
> +}
> +
>  #define STEP   8   /* 8 characters fill uint32_t bitmap */
>  #define SPACE  8   /* space for non-hex characters in vcpu str */
>  #define MAX_VCPU_STR_LEN    ((HVM_MAX_VCPUS + 3)/4 + SPACE)
> @@ -5569,6 +5597,8 @@ int main(int argc, char **argv, char **envp)
>          exit(1);
>      }
>  
> +    vcpu_sanity_check();
> +
>      if (nographic) {
>         if (serial_device_index == 0)
>             serial_devices[0] = "stdio";



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel