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

[Xen-changelog] [xen stable-4.3] fix listing of vcpus when domains lacking any vcpus exist



commit fccb5892c8fc3c191592fb933a0e044260f4f069
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Thu Nov 13 09:52:09 2014 +0100
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu Nov 13 09:52:09 2014 +0100

    fix listing of vcpus when domains lacking any vcpus exist
    
    On a system which looks like this:
    
    [root@st04 ~]# xl list
    Name                                        ID   Mem VCPUs      State   
Time(s)
    Domain-0                                     0   752     4     r-----   
46699.3
    (null)                                       1     0     0     --p---       
0.0
    (null)                                       2     0     0     --p---       
0.0
    (null)                                       3     0     0     --p---       
0.0
    badger                                      25     0     1     --p---       
0.0
    
    `xl vcpu-list` failes as so:
    
    [root@st04 ~]# xl vcpu-list
    Name                                ID  VCPU   CPU State   Time(s) CPU 
Affinity
    Domain-0                             0     0    0   -b-   12171.0  all
    Domain-0                             0     1    1   -b-   11779.6  all
    Domain-0                             0     2    2   -b-   11599.0  all
    Domain-0                             0     3    3   r--   11007.0  all
    libxl: critical: libxl__calloc: libxl: FATAL ERROR: memory allocation 
failure (libxl__calloc, 4294935299 x 40)
    : Cannot allocate memory
    libxl: FATAL ERROR: memory allocation failure (libxl__calloc, 4294935299 x 
40)
    
    The root cause of this is in Xen.  getdomaininfo() has no way of expressing
    "this domain has no vcpus".  Previously, info->max_vcpu_id would be returned
    uninitialised in such a case.
    
    Unfortunately, setting it to 0 as a default is not appropriate.  A 
max_vcpu_id
    of 0 and nr_online_cpus of 0 is the valid state for a single vcpu domain 
which
    is in the process of being destroyed.
    
    As all components are required to add 1 to max_vcpu_id to get the number of
    vcpus, an id of ~0U is not valid to be used.  Explicitly define this as an
    invalid max vcpu value, and use it to express "no vcpus" in getdomaininfo()
    
    In libxl, the issue is seen as libxl_list_vcpu() attempts to use the
    uninitialised domaininfo.max_vcpu_id for memory allocation.
    
    Check domaininfo.max_vcpu_id against the new sentinel value
    XEN_INVALID_MAX_VCPU_ID, and return early.  This means that it is now valid
    for libxl_list_vcpu() to return NULL for a domain which lacks any vcpus.
    
    As part of this change, remove the pointless call to libxl_get_max_cpus(),
    whose returned value is unconditionally clobbered in the for() loop.
    
    Reported-by: Euan Harris <euan.harris@xxxxxxxxxx>
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Don Slutz <dslutz@xxxxxxxxxxx>
    Acked-by: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
    
    tools/libxl: Fix libxl_list_vcpu() following c/s 93e52d52
    
    My reasoning regarding nr_cpus_out was wrong, as I had confused nr_cpus_out
    with nr_vcpus_out.
    
    Dario pointed this out, but the patch (having gained appropriate acks) got
    committed before I could post a correction.
    
    Noticed-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
    CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
    CC: Wei Liu <wei.liu2@xxxxxxxxxx>
    Reviewed-by: Dario Faggioli <dario.faggioli@xxxxxxxxxx>
    Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
    master commit: 93e52d5242804ff928131553599afa769f85481b
    master date: 2014-10-23 10:19:53 +0200
    master commit: c90a755f261b8ccb3dac7e1f695122cac95c6053
    master date: 2014-10-23 12:29:00 +0100
---
 tools/libxl/libxl.c         |    5 +++++
 tools/libxl/xl_cmdimpl.c    |    4 +---
 xen/common/domctl.c         |    1 +
 xen/include/public/domctl.h |    1 +
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 3d9543b..75f5053 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -4171,6 +4171,11 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t 
domid,
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "getting infolist");
         return NULL;
     }
+
+    if (domaininfo.max_vcpu_id == XEN_INVALID_MAX_VCPU_ID) {
+        return NULL;
+    }
+
     *nr_vcpus_out = libxl_get_max_cpus(ctx);
     ret = ptr = calloc(domaininfo.max_vcpu_id + 1, sizeof (libxl_vcpuinfo));
     if (!ptr) {
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index a7f888c..b251f4c 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -4384,10 +4384,8 @@ static void print_domain_vcpuinfo(uint32_t domid, 
uint32_t nr_cpus)
 
     vcpuinfo = libxl_list_vcpu(ctx, domid, &nb_vcpu, &nrcpus);
 
-    if (!vcpuinfo) {
-        fprintf(stderr, "libxl_list_vcpu failed.\n");
+    if (!vcpuinfo)
         return;
-    }
 
     for (i = 0; i < nb_vcpu; i++) {
         print_vcpuinfo(domid, &vcpuinfo[i], nr_cpus);
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 2747dcd..9988293 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -154,6 +154,7 @@ void getdomaininfo(struct domain *d, struct 
xen_domctl_getdomaininfo *info)
     struct vcpu_runstate_info runstate;
     
     info->domain = d->domain_id;
+    info->max_vcpu_id = XEN_INVALID_MAX_VCPU_ID;
     info->nr_online_vcpus = 0;
     info->ssidref = 0;
     
diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h
index 4c5b2bb..d381903 100644
--- a/xen/include/public/domctl.h
+++ b/xen/include/public/domctl.h
@@ -101,6 +101,7 @@ struct xen_domctl_getdomaininfo {
     uint64_aligned_t shared_info_frame; /* GMFN of shared_info struct */
     uint64_aligned_t cpu_time;
     uint32_t nr_online_vcpus;    /* Number of VCPUs currently online. */
+#define XEN_INVALID_MAX_VCPU_ID (~0U) /* Domain has no vcpus? */
     uint32_t max_vcpu_id;        /* Maximum VCPUID in use by this domain. */
     uint32_t ssidref;
     xen_domain_handle_t handle;
--
generated by git-patchbot for /home/xen/git/xen.git#stable-4.3

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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