mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 10:11:27 +01:00
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@citrix.com> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Acked-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Don Slutz <dslutz@verizon.com> Acked-by: Ian Campbell <Ian.Campbell@citrix.com>