libxl: memory size in kb requires 64 bit variable
PATCH 1/1 libxl: memory size in kb requires 64 bit variable
libxl_set_memory_target() and several other interface functions of libxl use a 32 bit sized parameter for a memory size value in kBytes. This limits the maximum size to be passed in such a parameter depending on signedness of the parameter to 2TB or 4TB.
Correct this by using 64 bit types.
--- tools/libxl/libxl.c | 72 ++++++++++++++++++------------------- tools/libxl/libxl.h | 84 ++++++++++++++++++++++++++++++++++++++++---- tools/libxl/libxl_dom.c | 4 +-- tools/libxl/libxl_internal.h | 4 +-- tools/libxl/libxl_numa.c | 6 ++-- tools/libxl/xl_cmdimpl.c | 2 +- 6 files changed, 121 insertions(+), 51 deletions(-)
tools/libxl/libxl.c +36 -36
@@ -4718,11 +4718,11 @@ out:/******************************************************************************/ -int libxl_domain_setmaxmem (libxl_ctx *ctx,uint32_t domid,uint32_t max_memkb) +int libxl_domain_setmaxmem (libxl_ctx *ctx,uint32_t domid,uint64_t max_memkb) {GC_INIT (ctx);char *mem, *endptr; -uint32_t memorykb; +uint64_t memorykb;char *dompath =libxl__xs_get_dompath (gc, domid);int rc =1 ;libxl__domain_userdata_lock *lock =NULL ;
@@ -4740,7 +4740,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb)LOGE (ERROR ,"cannot get memory info from %s/memory/target" , dompath); goto out; } - memorykb =strtoul (mem, &endptr,10 ); + memorykb =strtoull (mem, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid memory %s from %s/memory/target\n" , mem, dompath); goto out;
@@ -4753,7 +4753,8 @@ int libxl_domain_setmaxmem(libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb) } rc =xc_domain_setmaxmem (ctx->xch, domid, max_memkb +LIBXL_MAXMEM_CONSTANT );if (rc !=0 ) { -LOGE (ERROR ,"xc_domain_setmaxmem domid=%d memkb=%d failed ""rc=%d\n" , +LOGE (ERROR , +"xc_domain_setmaxmem domid=%d memkb=%" PRIu64" failed ""rc=%d\n" , domid, max_memkb +LIBXL_MAXMEM_CONSTANT , rc); goto out; }
@@ -4766,8 +4767,8 @@ out:return rc; } -static int libxl__fill_dom0_memory_info (libxl__gc *gc,uint32_t *target_memkb, -uint32_t *max_memkb) +static int libxl__fill_dom0_memory_info (libxl__gc *gc,uint64_t *target_memkb, +uint64_t *max_memkb) {int rc;libxl_dominfo info;
@@ -4791,7 +4792,7 @@ retry_transaction: }if (target) { - *target_memkb =strtoul (target, &endptr,10 ); + *target_memkb =strtoull (target, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid memory target %s from %s\n" , target, target_path);
@@ -4801,7 +4802,7 @@ retry_transaction: }if (staticmax) { - *max_memkb =strtoul (staticmax, &endptr,10 ); + *max_memkb =strtoull (staticmax, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid memory static-max %s from %s\n" , staticmax, max_path);
@@ -4821,14 +4822,12 @@ retry_transaction: goto out;if (target ==NULL ) { -libxl__xs_printf (gc, t, target_path,"%" PRIu32, - (uint32_t ) info.current_memkb); - *target_memkb = (uint32_t ) info.current_memkb; +libxl__xs_printf (gc, t, target_path,"%" PRIu64, info.current_memkb); + *target_memkb = info.current_memkb; }if (staticmax ==NULL ) { -libxl__xs_printf (gc, t, max_path,"%" PRIu32, - (uint32_t ) info.max_memkb); - *max_memkb = (uint32_t ) info.max_memkb; +libxl__xs_printf (gc, t, max_path,"%" PRIu64, info.max_memkb); + *max_memkb = info.max_memkb; } rc =0 ;
@@ -4846,14 +4845,14 @@ out: }int libxl_set_memory_target (libxl_ctx *ctx,uint32_t domid, -int32_t target_memkb,int relative,int enforce) +int64_t target_memkb,int relative,int enforce) {GC_INIT (ctx);int rc, r, lrc, abort_transaction =0 ;uint64_t memorykb; -uint32_t videoram =0 ; -uint32_t current_target_memkb =0 , new_target_memkb =0 ; -uint32_t current_max_memkb =0 ; +uint64_t videoram =0 ; +uint64_t current_target_memkb =0 , new_target_memkb =0 ; +uint64_t current_max_memkb =0 ;char *memmax, *endptr, *videoram_s =NULL , *target =NULL ;char *dompath =libxl__xs_get_dompath (gc, domid);xc_domaininfo_t info;
@@ -4890,7 +4889,7 @@ retry_transaction: rc =ERROR_FAIL ; goto out; }else { - current_target_memkb =strtoul (target, &endptr,10 ); + current_target_memkb =strtoull (target, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid memory target %s from %s/memory/target\n" , target, dompath);
@@ -4907,7 +4906,7 @@ retry_transaction: rc =ERROR_FAIL ; goto out; } - memorykb =strtoul (memmax, &endptr,10 ); + memorykb =strtoull (memmax, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid max memory %s from %s/memory/static-max\n" , memmax, dompath);
@@ -4937,7 +4936,8 @@ retry_transaction: }if (!domid && new_target_memkb <LIBXL_MIN_DOM0_MEM ) { -LOG (ERROR ,"new target %d for dom0 is below the minimum threshold" , +LOG (ERROR , +"new target %" PRIu64" for dom0 is below the minimum threshold" , new_target_memkb); abort_transaction =1 ; rc =ERROR_INVAL ;
@@ -4964,7 +4964,7 @@ retry_transaction: (new_target_memkb + LIBXL_MAXMEM_CONSTANT) / 4, NULL, NULL, NULL);if (r !=0 ) {LOGE (ERROR , -"xc_domain_set_pod_target domid=%d, memkb=%d ""failed rc=%d\n" , +"xc_domain_set_pod_target domid=%d, memkb=%" PRIu64" failed rc=%d\n" , domid, new_target_memkb /4 , r);
@@ -4974,13 +4974,13 @@ retry_transaction: }libxl__xs_printf (gc, t,GCSPRINTF ("%s/memory/target" , dompath), -"%" PRIu32, new_target_memkb); +"%" PRIu64, new_target_memkb);libxl_dominfo_init (&ptr);xcinfo2xlinfo (ctx, &info, &ptr); uuid =libxl__uuid2string (gc, ptr.uuid);libxl__xs_printf (gc, t,GCSPRINTF ("/vm/%s/memory" , uuid), -"%" PRIu32, new_target_memkb /1024 ); +"%" PRIu64, new_target_memkb /1024 );libxl_dominfo_dispose (&ptr); rc =0 ;
@@ -4999,13 +4999,13 @@ out_no_transaction:/* out_target_memkb and out_max_memkb can be NULL */ static int libxl__get_memory_target (libxl__gc *gc,uint32_t domid, -uint32_t *out_target_memkb, -uint32_t *out_max_memkb) +uint64_t *out_target_memkb, +uint64_t *out_max_memkb) {int rc;char *target =NULL , *static_max =NULL , *endptr =NULL ;char *dompath =libxl__xs_get_dompath (gc, domid); -uint32_t target_memkb, max_memkb; +uint64_t target_memkb, max_memkb; target =libxl__xs_read (gc,XBT_NULL ,GCSPRINTF ("%s/memory/target" , dompath));
@@ -5028,13 +5028,13 @@ static int libxl__get_memory_target(libxl__gc *gc, uint32_t domid, dompath); goto out; }else { - target_memkb =strtoul (target, &endptr,10 ); + target_memkb =strtoull (target, &endptr,10 );if (*endptr !='\0' ) {LOGE (ERROR ,"invalid memory target %s from %s/memory/target\n" , target, dompath); goto out; } - max_memkb =strtoul (static_max, &endptr,10 ); + max_memkb =strtoull (static_max, &endptr,10 );if (*endptr !='\0' ) { LOGE(ERROR, "invalid memory target %s from %s/memory/static-max\n",
@@ -5058,7 +5058,7 @@ out: }int libxl_get_memory_target (libxl_ctx *ctx,uint32_t domid, -uint32_t *out_target) +uint64_t *out_target) {GC_INIT (ctx);int rc;
@@ -5071,7 +5071,7 @@ int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid,int libxl_domain_need_memory (libxl_ctx *ctx,const libxl_domain_build_info *b_info_in, -uint32_t *need_memkb) +uint64_t *need_memkb) {GC_INIT (ctx);libxl_domain_build_info b_info[1 ];
@@ -5107,7 +5107,7 @@ out: } -int libxl_get_free_memory (libxl_ctx *ctx,uint32_t *memkb) +int libxl_get_free_memory (libxl_ctx *ctx,uint64_t *memkb) {int rc =0 ;libxl_physinfo info;
@@ -5124,8 +5124,8 @@ out:return rc; } -int libxl_wait_for_free_memory (libxl_ctx *ctx,uint32_t domid,uint32_t - memory_kb,int wait_secs) +int libxl_wait_for_free_memory (libxl_ctx *ctx,uint32_t domid, +uint64_t memory_kb,int wait_secs) {int rc =0 ;libxl_physinfo info;
@@ -5152,7 +5152,7 @@ out:int libxl_wait_for_memory_target (libxl_ctx *ctx,uint32_t domid,int wait_secs) {int rc =0 ; -uint32_t target_memkb =0 ; +uint64_t target_memkb =0 ;uint64_t current_memkb, prev_memkb;libxl_dominfo info;
@@ -7368,7 +7368,7 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,* "target" and "static-max". */ { -uint32_t target_memkb =0 , max_memkb =0 ; +uint64_t target_memkb =0 , max_memkb =0 ;/* "target" */ rc =libxl__get_memory_target (gc, domid, &target_memkb, &max_memkb);
tools/libxl/libxl.h +77 -7
110 lines not on this page · raw message
tools/libxl/libxl_dom.c +2 -2
@@ -123,7 +123,7 @@ static int numa_place_domain(libxl__gc *gc, uint32_t domid,libxl_bitmap cpupool_nodemap;libxl_cpupoolinfo cpupool_info;int i, cpupool, rc =0 ; -uint32_t memkb; +uint64_t memkb;libxl__numa_candidate_init (&candidate);libxl_bitmap_init (&cpupool_nodemap);
@@ -178,7 +178,7 @@ static int numa_place_domain(libxl__gc *gc, uint32_t domid, }LOG (DETAIL ,"NUMA placement candidate with %d nodes, %d cpus and " -"%" PRIu32" KB free selected" , candidate.nr_nodes, +"%" PRIu64" KB free selected" , candidate.nr_nodes, candidate.nr_cpus, candidate.free_memkb /1024 ); out:
tools/libxl/libxl_internal.h +2 -2
@@ -3892,7 +3892,7 @@ static inline void libxl__ctx_unlock(libxl_ctx *ctx) {typedef struct {int nr_cpus, nr_nodes;int nr_vcpus; -uint32_t free_memkb; +uint64_t free_memkb;libxl_bitmap nodemap; }libxl__numa_candidate ;
@@ -3932,7 +3932,7 @@ typedef int (*libxl__numa_candidate_cmpf)(const libxl__numa_candidate *c1,* it. */ _hidden int libxl__get_numa_candidate(libxl__gc *gc, - uint32_t min_free_memkb, int min_cpus, + uint64_t min_free_memkb, int min_cpus, int min_nodes, int max_nodes, const libxl_bitmap *suitable_cpumap, libxl__numa_candidate_cmpf numa_cmpf,
tools/libxl/libxl_numa.c +3 -3
@@ -285,7 +285,7 @@ static int count_cpus_per_node(libxl_cputopology *tinfo, int nr_cpus,* comparison function. */ int libxl__get_numa_candidate(libxl__gc *gc, - uint32_t min_free_memkb, int min_cpus, + uint64_t min_free_memkb, int min_cpus, int min_nodes, int max_nodes, const libxl_bitmap *suitable_cpumap, libxl__numa_candidate_cmpf numa_cmpf,
@@ -436,7 +436,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,for (comb_ok =comb_init (gc, &comb_iter, nr_suit_nodes, min_nodes); comb_ok; comb_ok =comb_next (comb_iter, nr_suit_nodes, min_nodes)) { -uint32_t nodes_free_memkb; +uint64_t nodes_free_memkb;int nodes_cpus;/* Get the nodemap for the combination, only considering
@@ -478,7 +478,7 @@ int libxl__get_numa_candidate(libxl__gc *gc,LOG (DEBUG ,"New best NUMA placement candidate found: " "nr_nodes=%d, nr_cpus=%d, nr_vcpus=%d, " -"free_memkb=%" PRIu32"" , new_cndt.nr_nodes, +"free_memkb=%" PRIu64"" , new_cndt.nr_nodes, new_cndt.nr_cpus, new_cndt.nr_vcpus, new_cndt.free_memkb /1024 );
tools/libxl/xl_cmdimpl.c +1 -1
@@ -2688,7 +2688,7 @@ static int preserve_domain(uint32_t *r_domid, libxl_event *event,static bool freemem (uint32_t domid,libxl_domain_build_info *b_info) {int rc, retries =3 ; -uint32_t need_memkb, free_memkb; +uint64_t need_memkb, free_memkb;if (!autoballoon)return true;
Signature · 7 lines
2.6.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Juergen Gross writes ("[PATCH] libxl: memory size in kb requires 64 bit variable"):
Quoted 4 lines
libxl_set_memory_target()and several other interface functions of libxl use a 32 bit sized parameter for a memory size value in kBytes. This limits the maximum size to be passed in such a parameter depending on signedness of the parameter to 2TB or 4TB.
This is the right interface change, I think. But:
tools/libxl/libxl.h int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_t memory_k · line 1429
Quoted 5 lines
tools/libxl/libxl.h +5
-0+#if defined(LIBXL_API_VERSION ) &&LIBXL_API_VERSION <0x040800 + +static inline int libxl_get_memory_target_0x040700( + libxl_ctx *ctx, uint32_t domid, uint32_t *out_target) + LIBXL_EXTERNAL_CALLERS_ONLY
Firstly, this is rather too much to be an inline function. It is perfectly permissible to m,ake one of these compatibility functions extern rather than inline.
tools/libxl/libxl.h int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_t memory_k · line 1438
Quoted 4 lines
tools/libxl/libxl.h +4
-0+ *out_target = my_out_target; +if (my_out_target != *out_target) { +LOGE (ERROR ,"memory size too large for 32 bit value\n" ); + ret =ERROR_FAIL ;
Secondly, this is rather repetitive. I wonder if it could be made less so.
Thanks,
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines · Ian Jackson
Juergen Gross writes ("[PATCH] libxl: memory size in kb requires 64 bit variable"):
Quoted 4 lines
libxl_set_memory_target()and several other interface functions of libxl use a 32 bit sized parameter for a memory size value in kBytes. This limits the maximum size to be passed in such a parameter depending on signedness of the parameter to 2TB or 4TB.This is the right interface change, I think. But:
Quoted 9 lines
tools/libxl/libxl.h int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_t memory_k · line 1429
Quoted 5 lines
tools/libxl/libxl.h +5
-0+#if defined(LIBXL_API_VERSION ) &&LIBXL_API_VERSION <0x040800 + +static inline int libxl_get_memory_target_0x040700( + libxl_ctx *ctx, uint32_t domid, uint32_t *out_target) + LIBXL_EXTERNAL_CALLERS_ONLYFirstly, this is rather too much to be an inline function. It is perfectly permissible to m,ake one of these compatibility functions extern rather than inline.
Okay.
Quoted 7 lines
tools/libxl/libxl.h int libxl_wait_for_free_memory(libxl_ctx *ctx, uint32_t domid, uint32_t memory_k · line 1438
Quoted 4 lines
tools/libxl/libxl.h +4
-0+ *out_target = my_out_target; +if (my_out_target != *out_target) { +LOGE (ERROR ,"memory size too large for 32 bit value\n" ); + ret =ERROR_FAIL ;Secondly, this is rather repetitive. I wonder if it could be made less so.
Sure.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel