libxl/xl: fix multivcpu handling
PATCH 1/1 libxl/xl: fix multivcpu handling
Hi all,
currently libxl and xl are incapable of handling multivcpus guests correctly, this patch fixes it.
Signed-off-by Stefano Stabellini <[email protected]>
---
tools/libxl/libxl.c +8 -0
@@ -875,6 +875,14 @@if (info->apic) {flexarray_set (dm_args, num++,"-acpi" ); } +if (info->vcpus) { +flexarray_set (dm_args, num++,"-vcpus" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +if (info->vcpu_avail) { +flexarray_set (dm_args, num++,"-vcpu_avail" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"0x%x" , info->vcpu_avail)); + }for (i =0 ; i < num_vifs; i++) {if (vifs[i].nictype ==NICTYPE_IOEMU ) { char *smac = libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
tools/libxl/libxl.h +2 -0
@@ -162,6 +162,8 @@bool usb;/* usb support enabled or disabled */ char *usbdevice;/* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */ bool apic;/* apic enabled or disabled */ +int vcpus;/* max number of vcpus */ +int vcpu_avail;/* vcpus actually available */ char **extra;/* extra parameters pass directly to qemu, NULL terminated */ /* Network is missing */ } libxl_device_model_info;
tools/libxl/libxl_dom.c +4 -6
@@ -100,7 +100,7 @@xc_cpuid_apply_policy (ctx->xch, domid);#endif - ents =libxl_calloc (ctx, (12 + info->max_vcpus) *2 ,sizeof (char *)); + ents =libxl_calloc (ctx,12 + (info->max_vcpus *2 ) +2 ,sizeof (char *)); ents[0 ] ="memory/static-max" ; ents[1 ] =libxl_sprintf (ctx,"%d" , info->max_memkb); ents[2 ] ="memory/target" ;
@@ -115,7 +115,7 @@ ents[11 ] =libxl_sprintf (ctx,"%lu" , state->store_mfn);for (i =0 ; i < info->max_vcpus; i++) { ents[12 +(i*2 )] =libxl_sprintf (ctx,"cpu/%d/availability" , i); - ents[12 +(i*2 )+1 ] = (i && info->cur_vcpus && (i >= info->cur_vcpus)) + ents[12 +(i*2 )+1 ] = (i && info->cur_vcpus && !(info->cur_vcpus & (1 << i))) ?"offline" :"online" ; }
@@ -182,10 +182,8 @@XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , ret,"hvm building failed" );return ERROR_FAIL ; } - ret =hvm_build_set_params (ctx->xch, domid, info->u.hvm.apic, info->u.hvm.acpi, - info->u.hvm.pae, info->u.hvm.nx, info->u.hvm.viridian, - info->max_vcpus, - state->store_port, &state->store_mfn); + ret =hvm_build_set_params (ctx->xch, domid, info, state->store_port, + &state->store_mfn);if (ret) {XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , ret,"hvm build set params failed" );return ERROR_FAIL ;
tools/libxl/libxl_internal.h +2 -2
@@ -166,8 +166,8 @@/* from xenguest (helper */ int hvm_build_set_params (xc_interface *handle,uint32_t domid, -int apic,int acpi,int pae,int nx,int viridian, -int vcpus,int store_evtchn,unsigned long *store_mfn); +libxl_domain_build_info *info, +int store_evtchn,unsigned long *store_mfn);/* xl_exec */
tools/libxl/xenguest.c +11 -7
@@ -17,10 +17,13 @@#include <xenguest.h> #include <sys/mman.h> #include <xen/hvm/hvm_info_table.h> +#include <string.h> + +#include "libxl.h" int hvm_build_set_params (xc_interface *handle,uint32_t domid, -int apic,int acpi,int pae,int nx,int viridian, -int vcpus,int store_evtchn,unsigned long *store_mfn) +libxl_domain_build_info *info, +int store_evtchn,unsigned long *store_mfn) {struct hvm_info_table *va_hvm;uint8_t *va_map, sum;
@@ -33,18 +36,19 @@return -1 ; va_hvm = (struct hvm_info_table *)(va_map +HVM_INFO_OFFSET ); - va_hvm->acpi_enabled = acpi; - va_hvm->apic_mode = apic; - va_hvm->nr_vcpus = vcpus; + va_hvm->acpi_enabled = info->u.hvm.acpi; + va_hvm->apic_mode = info->u.hvm.apic; + va_hvm->nr_vcpus = info->max_vcpus; +memcpy (va_hvm->vcpu_online, &info->cur_vcpus,sizeof (info->cur_vcpus));for (i =0 , sum =0 ; i < va_hvm->length; i++) sum += ((uint8_t *) va_hvm)[i]; va_hvm->checksum -= sum;munmap (va_map,XC_PAGE_SIZE );xc_get_hvm_param (handle, domid,HVM_PARAM_STORE_PFN , store_mfn); -xc_set_hvm_param (handle, domid,HVM_PARAM_PAE_ENABLED , pae); +xc_set_hvm_param (handle, domid,HVM_PARAM_PAE_ENABLED , info->u.hvm.pae);#if defined(__i386__) || defined(__x86_64__) -xc_set_hvm_param (handle, domid,HVM_PARAM_VIRIDIAN , viridian); +xc_set_hvm_param (handle, domid,HVM_PARAM_VIRIDIAN , info->u.hvm.viridian);#endif xc_set_hvm_param (handle, domid,HVM_PARAM_STORE_EVTCHN , store_evtchn);return 0 ;
tools/libxl/xl_cmdimpl.c +5 -1
@@ -204,6 +205,8 @@ dm_info->device_model ="qemu-dm" ; dm_info->videoram = b_info->video_memkb /1024 ; dm_info->apic = b_info->u.hvm.apic; + dm_info->vcpus = b_info->max_vcpus; + dm_info->vcpu_avail = b_info->cur_vcpus; dm_info->stdvga =0 ; dm_info->vnc =1 ;
@@ -466,8 +471,10 @@init_build_info (b_info, c_info);/* the following is the actual config parsing with overriding values in the structures */ -if (!xlu_cfg_get_long (config,"vcpus" , &l)) +if (!xlu_cfg_get_long (config,"vcpus" , &l)) { b_info->max_vcpus = l; + b_info->cur_vcpus = (1 << l) -1 ; + }if (!xlu_cfg_get_long (config,"memory" , &l)) { b_info->max_memkb = l *1024 ;
Quoted 14 lines · Stefano Stabellini
Hi all,
currently libxl and xl are incapable of handling multivcpus guests correctly, this patch fixes it.Signed-off-by Stefano Stabellini<[email protected]>---
diff -r
4ab68bf4c37etools/libxl/libxl.c
tools/libxl/libxl.c line 881
Quoted 7 lines
tools/libxl/libxl.c +4
-0@@ -875,6 +875,14 @@if (info->apic) {flexarray_set (dm_args, num++,"-acpi" ); } +if (info->vcpus) { +flexarray_set (dm_args, num++,"-vcpus" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + }
should be either if (info->vcpus > 1) or no test at all and info->vcpus == 0 should return with invalid argument.
Signature · 1 line
Vincent
Quoted 11 lines · Vincent Hanquez
Quoted 10 lines · Stefano Stabellini
Hi all,
currently libxl and xl are incapable of handling multivcpus guests correctly, this patch fixes it.Signed-off-by Stefano Stabellini<[email protected]>---
Quoted 15 lines
tools/libxl/libxl.c line 881
Quoted 11 lines
diff -r
4ab68bf4c37etools/libxl/libxl.ctools/libxl/libxl.c +4
-0@@ -875,6 +875,14 @@if (info->apic) {flexarray_set (dm_args, num++,"-acpi" ); } +if (info->vcpus) { +flexarray_set (dm_args, num++,"-vcpus" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + }should be either if (
info->vcpus> 1) or no test at all andinfo->vcpus== 0 should return with invalid argument.
Yes, you are right
---
tools/libxl/libxl.c +8 -0
@@ -875,6 +875,14 @@if (info->apic) {flexarray_set (dm_args, num++,"-acpi" ); } +if (info->vcpus >1 ) { +flexarray_set (dm_args, num++,"-vcpus" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"%d" , info->vcpus)); + } +if (info->vcpu_avail) { +flexarray_set (dm_args, num++,"-vcpu_avail" ); +flexarray_set (dm_args, num++,libxl_sprintf (ctx,"0x%x" , info->vcpu_avail)); + }for (i =0 ; i < num_vifs; i++) {if (vifs[i].nictype ==NICTYPE_IOEMU ) { char *smac = libxl_sprintf(ctx, "%02x:%02x:%02x:%02x:%02x:%02x",
tools/libxl/libxl.h +2 -0
@@ -162,6 +162,8 @@bool usb;/* usb support enabled or disabled */ char *usbdevice;/* enable usb mouse: tablet for absolute mouse, mouse for PS/2 protocol relative mouse */ bool apic;/* apic enabled or disabled */ +int vcpus;/* max number of vcpus */ +int vcpu_avail;/* vcpus actually available */ char **extra;/* extra parameters pass directly to qemu, NULL terminated */ /* Network is missing */ } libxl_device_model_info;
tools/libxl/libxl_dom.c +4 -6
@@ -100,7 +100,7 @@xc_cpuid_apply_policy (ctx->xch, domid);#endif - ents =libxl_calloc (ctx, (12 + info->max_vcpus) *2 ,sizeof (char *)); + ents =libxl_calloc (ctx,12 + (info->max_vcpus *2 ) +2 ,sizeof (char *)); ents[0 ] ="memory/static-max" ; ents[1 ] =libxl_sprintf (ctx,"%d" , info->max_memkb); ents[2 ] ="memory/target" ;
@@ -115,7 +115,7 @@ ents[11 ] =libxl_sprintf (ctx,"%lu" , state->store_mfn);for (i =0 ; i < info->max_vcpus; i++) { ents[12 +(i*2 )] =libxl_sprintf (ctx,"cpu/%d/availability" , i); - ents[12 +(i*2 )+1 ] = (i && info->cur_vcpus && (i >= info->cur_vcpus)) + ents[12 +(i*2 )+1 ] = (i && info->cur_vcpus && !(info->cur_vcpus & (1 << i))) ?"offline" :"online" ; }
@@ -182,10 +182,8 @@XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , ret,"hvm building failed" );return ERROR_FAIL ; } - ret =hvm_build_set_params (ctx->xch, domid, info->u.hvm.apic, info->u.hvm.acpi, - info->u.hvm.pae, info->u.hvm.nx, info->u.hvm.viridian, - info->max_vcpus, - state->store_port, &state->store_mfn); + ret =hvm_build_set_params (ctx->xch, domid, info, state->store_port, + &state->store_mfn);if (ret) {XL_LOG_ERRNOVAL (ctx,XL_LOG_ERROR , ret,"hvm build set params failed" );return ERROR_FAIL ;
tools/libxl/libxl_internal.h +2 -2
@@ -166,8 +166,8 @@/* from xenguest (helper */ int hvm_build_set_params (xc_interface *handle,uint32_t domid, -int apic,int acpi,int pae,int nx,int viridian, -int vcpus,int store_evtchn,unsigned long *store_mfn); +libxl_domain_build_info *info, +int store_evtchn,unsigned long *store_mfn);/* xl_exec */
tools/libxl/xenguest.c +11 -7
@@ -17,10 +17,13 @@#include <xenguest.h> #include <sys/mman.h> #include <xen/hvm/hvm_info_table.h> +#include <string.h> + +#include "libxl.h" int hvm_build_set_params (xc_interface *handle,uint32_t domid, -int apic,int acpi,int pae,int nx,int viridian, -int vcpus,int store_evtchn,unsigned long *store_mfn) +libxl_domain_build_info *info, +int store_evtchn,unsigned long *store_mfn) {struct hvm_info_table *va_hvm;uint8_t *va_map, sum;
@@ -33,18 +36,19 @@return -1 ; va_hvm = (struct hvm_info_table *)(va_map +HVM_INFO_OFFSET ); - va_hvm->acpi_enabled = acpi; - va_hvm->apic_mode = apic; - va_hvm->nr_vcpus = vcpus; + va_hvm->acpi_enabled = info->u.hvm.acpi; + va_hvm->apic_mode = info->u.hvm.apic; + va_hvm->nr_vcpus = info->max_vcpus; +memcpy (va_hvm->vcpu_online, &info->cur_vcpus,sizeof (info->cur_vcpus));for (i =0 , sum =0 ; i < va_hvm->length; i++) sum += ((uint8_t *) va_hvm)[i]; va_hvm->checksum -= sum;munmap (va_map,XC_PAGE_SIZE );xc_get_hvm_param (handle, domid,HVM_PARAM_STORE_PFN , store_mfn); -xc_set_hvm_param (handle, domid,HVM_PARAM_PAE_ENABLED , pae); +xc_set_hvm_param (handle, domid,HVM_PARAM_PAE_ENABLED , info->u.hvm.pae);#if defined(__i386__) || defined(__x86_64__) -xc_set_hvm_param (handle, domid,HVM_PARAM_VIRIDIAN , viridian); +xc_set_hvm_param (handle, domid,HVM_PARAM_VIRIDIAN , info->u.hvm.viridian);#endif xc_set_hvm_param (handle, domid,HVM_PARAM_STORE_EVTCHN , store_evtchn);return 0 ;
tools/libxl/xl_cmdimpl.c +5 -1
@@ -204,6 +204,8 @@ dm_info->device_model ="qemu-dm" ; dm_info->videoram = b_info->video_memkb /1024 ; dm_info->apic = b_info->u.hvm.apic; + dm_info->vcpus = b_info->max_vcpus; + dm_info->vcpu_avail = b_info->cur_vcpus; dm_info->stdvga =0 ; dm_info->vnc =1 ;
@@ -466,8 +468,10 @@init_build_info (b_info, c_info);/* the following is the actual config parsing with overriding values in the structures */ -if (!xlu_cfg_get_long (config,"vcpus" , &l)) +if (!xlu_cfg_get_long (config,"vcpus" , &l)) { b_info->max_vcpus = l; + b_info->cur_vcpus = (1 << l) -1 ; + }if (!xlu_cfg_get_long (config,"memory" , &l)) { b_info->max_memkb = l *1024 ;