Message ID | 1343729663-20527-1-git-send-email-riegamaths@gmail.com |
---|---|
State | New |
Headers | show |
On 31 July 2012 11:14, <riegamaths@gmail.com> wrote: > > @@ -1256,6 +1274,13 @@ int kvm_init(void) > goto err; > } > > + max_vcpus = kvm_max_vcpus(s); > + if (smp_cpus > max_vcpus) { > + fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus " > + "supported by KVM (%d)\n", smp_cpus, max_vcpus); > + exit(1); Don't exit here, just use 'goto err' like all the other checks in this function. The caller will handle this and exit (or downgrade to TCG if the user wanted that). -- PMM
2012/7/31 Peter Maydell <peter.maydell@linaro.org>: > On 31 July 2012 11:14, <riegamaths@gmail.com> wrote: >> >> @@ -1256,6 +1274,13 @@ int kvm_init(void) >> goto err; >> } >> >> + max_vcpus = kvm_max_vcpus(s); >> + if (smp_cpus > max_vcpus) { >> + fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus " >> + "supported by KVM (%d)\n", smp_cpus, max_vcpus); >> + exit(1); > > Don't exit here, just use 'goto err' like all the other checks in > this function. The caller will handle this and exit (or downgrade > to TCG if the user wanted that). > Thanks for your review. I agree with you, I should use "goto err" like other checks. > -- PMM
diff --git a/kvm-all.c b/kvm-all.c index 2148b20..d1f7d72 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1207,6 +1207,23 @@ static int kvm_irqchip_create(KVMState *s) return 0; } +static int kvm_max_vcpus(KVMState *s) +{ + int max_vcpus = 4; + int ret; + ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS); + if (ret) { + max_vcpus = ret; + } else { + ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS); + if (ret) { + max_vcpus = ret; + } + } + + return max_vcpus; +} + int kvm_init(void) { static const char upgrade_note[] = @@ -1216,6 +1233,7 @@ int kvm_init(void) const KVMCapabilityInfo *missing_cap; int ret; int i; + int max_vcpus; s = g_malloc0(sizeof(KVMState)); @@ -1256,6 +1274,13 @@ int kvm_init(void) goto err; } + max_vcpus = kvm_max_vcpus(s); + if (smp_cpus > max_vcpus) { + fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus " + "supported by KVM (%d)\n", smp_cpus, max_vcpus); + exit(1); + } + s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0); if (s->vmfd < 0) { #ifdef TARGET_S390X