diff options
author | Dunrong Huang <riegamaths@gmail.com> | 2012-07-31 19:18:17 +0800 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2012-08-09 16:16:36 +0300 |
commit | 3ed444e949cd2f0938759836c0991dfabe86f485 (patch) | |
tree | 033d928759a09ef1ad160426bd317b2ef3812301 /kvm-all.c | |
parent | c03b0aa0ca93480e92dc356e58538df0835fe621 (diff) | |
download | hqemu-3ed444e949cd2f0938759836c0991dfabe86f485.zip hqemu-3ed444e949cd2f0938759836c0991dfabe86f485.tar.gz |
kvm: Check if smp_cpus exceeds max cpus supported by kvm
Add a helper function for fetching max cpus supported by kvm.
Make QEMU exit with an error message if smp_cpus exceeds limit
of VCPU count retrieved by invoking this helper function.
Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'kvm-all.c')
-rw-r--r-- | kvm-all.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -1207,6 +1207,26 @@ static int kvm_irqchip_create(KVMState *s) return 0; } +static int kvm_max_vcpus(KVMState *s) +{ + int ret; + + /* Find number of supported CPUs using the recommended + * procedure from the kernel API documentation to cope with + * older kernels that may be missing capabilities. + */ + ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS); + if (ret) { + return ret; + } + ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS); + if (ret) { + return ret; + } + + return 4; +} + int kvm_init(void) { static const char upgrade_note[] = @@ -1216,6 +1236,7 @@ int kvm_init(void) const KVMCapabilityInfo *missing_cap; int ret; int i; + int max_vcpus; s = g_malloc0(sizeof(KVMState)); @@ -1256,6 +1277,14 @@ int kvm_init(void) goto err; } + max_vcpus = kvm_max_vcpus(s); + if (smp_cpus > max_vcpus) { + ret = -EINVAL; + fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus " + "supported by KVM (%d)\n", smp_cpus, max_vcpus); + goto err; + } + s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0); if (s->vmfd < 0) { #ifdef TARGET_S390X |