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

[Xen-devel] [PATCH 1/2]: xl: Fix glibc crash dump in xl vcpu-{list, set}



Hi,

xc_vcpu_[sg]etaffinity require the number of _bytes_ needed for
holding a CPU map, not the number of bits. Fix this when
calling the function from libxl and rename the misleading variable
name to avoid future confusion.

Regards,
Andre.

Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

--
Andre Przywara
AMD-Operating System Research Center (OSRC), Dresden, Germany
Tel: +49 351 448-3567-12
commit a86856ace8f928ac05abdf39279165bef976630a
Author: Andre Przywara <andre.przywara@xxxxxxx>
Date:   Mon Aug 9 23:57:49 2010 +0200

    Fix glibc crash dump in xl vcpu-{list,set}
    
    xc_vcpu_[sg]etaffinity require the number of _bytes_ needed for
    holding a CPU map, not the number of bits. Fix this when
    calling the function from libxl and rename the misleading variable
    name to avoid future confusion.
    
    Signed-off-by: Andre Przywara <andre.przywara@xxxxxxx>

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 732772c..f5f4f87 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2536,7 +2536,7 @@ const libxl_version_info* 
libxl_get_version_info(libxl_ctx *ctx)
 }
 
 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
-                                       int *nb_vcpu, int *cpusize)
+                                       int *nb_vcpu, int *nrcpus)
 {
     libxl_vcpuinfo *ptr, *ret;
     xc_domaininfo_t domaininfo;
@@ -2551,7 +2551,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t 
domid,
         XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting physinfo");
         return NULL;
     }
-    *cpusize = physinfo.max_cpu_id + 1;
+    *nrcpus = physinfo.max_cpu_id + 1;
     ptr = libxl_calloc(ctx, domaininfo.max_vcpu_id + 1, sizeof 
(libxl_vcpuinfo));
     if (!ptr) {
         return NULL;
@@ -2559,7 +2559,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t 
domid,
 
     ret = ptr;
     for (*nb_vcpu = 0; *nb_vcpu <= domaininfo.max_vcpu_id; ++*nb_vcpu, ++ptr) {
-        ptr->cpumap = libxl_calloc(ctx, (*cpusize + 63) / 64, sizeof 
(uint64_t));
+        ptr->cpumap = libxl_calloc(ctx, (*nrcpus + 63) / 64, sizeof 
(uint64_t));
         if (!ptr->cpumap) {
             return NULL;
         }
@@ -2567,7 +2567,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t 
domid,
             XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting vcpu info");
             return NULL;
         }
-        if (xc_vcpu_getaffinity(ctx->xch, domid, *nb_vcpu, ptr->cpumap, 
*cpusize) == -1) {
+        if (xc_vcpu_getaffinity(ctx->xch, domid, *nb_vcpu,
+            ptr->cpumap, ((*nrcpus) + 7) / 8) == -1) {
             XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "getting vcpu affinity");
             return NULL;
         }
@@ -2582,9 +2583,9 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t 
domid,
 }
 
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
-                           uint64_t *cpumap, int cpusize)
+                           uint64_t *cpumap, int nrcpus)
 {
-    if (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, cpusize)) {
+    if (xc_vcpu_setaffinity(ctx->xch, domid, vcpuid, cpumap, (nrcpus + 7) / 
8)) {
         XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "setting vcpu affinity");
         return ERROR_FAIL;
     }
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index 46b949d..2002a07 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -594,9 +594,9 @@ typedef struct {
 
 int libxl_get_physinfo(libxl_ctx *ctx, libxl_physinfo *physinfo);
 libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
-                                       int *nb_vcpu, int *cpusize);
+                                       int *nb_vcpu, int *nrcpus);
 int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
-                           uint64_t *cpumap, int cpusize);
+                           uint64_t *cpumap, int nrcpus);
 int libxl_set_vcpucount(libxl_ctx *ctx, uint32_t domid, uint32_t count);
 
 int libxl_get_sched_id(libxl_ctx *ctx);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 97b882d..e0bdf0c 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -3249,7 +3249,7 @@ void vcpulist(int argc, char **argv)
     libxl_dominfo *dominfo;
     libxl_vcpuinfo *vcpuinfo;
     libxl_physinfo physinfo;
-    int nb_vcpu, nb_domain, cpusize;
+    int nb_vcpu, nb_domain, nrcpus;
 
     if (libxl_get_physinfo(&ctx, &physinfo) != 0) {
         fprintf(stderr, "libxl_physinfo failed.\n");
@@ -3263,7 +3263,8 @@ void vcpulist(int argc, char **argv)
             goto vcpulist_out;
         }
         for (; nb_domain > 0; --nb_domain, ++dominfo) {
-            if (!(vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu, 
&cpusize))) {
+            if (!(vcpuinfo = libxl_list_vcpu(&ctx, dominfo->domid, &nb_vcpu,
+                &nrcpus))) {
                 fprintf(stderr, "libxl_list_vcpu failed.\n");
                 goto vcpulist_out;
             }
@@ -3276,7 +3277,7 @@ void vcpulist(int argc, char **argv)
             if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
                 fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
             }
-            if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, 
&cpusize))) {
+            if (!(vcpuinfo = libxl_list_vcpu(&ctx, domid, &nb_vcpu, &nrcpus))) 
{
                 fprintf(stderr, "libxl_list_vcpu failed.\n");
                 goto vcpulist_out;
             }
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

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