kvm: warn if num cpus is greater than num recommended
PATCH 1/1 kvm: warn if num cpus is greater than num recommended
The comment in kvm_max_vcpus() states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should check KVM_CAP_NR_VCPUS for the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.
--- kvm-all.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)
kvm-all.c +27 -18
@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )
@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_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; +fprintf (stderr, +"Warning: Number of SMP cpus requested (%d) exceeds " +"recommended cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + + 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 );
Signature · 1 line
1.8.1.4
Quoted 9 lines · Andrew Jones
The comment in
kvm_max_vcpus()states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should checkKVM_CAP_NR_VCPUSfor the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.Signed-off-by Andrew Jones <[email protected]>
CCing libvir-list. It is probably interesting for libvirt to expose or warn about the recommended VCPU limit somehow, and in this case a simple warning on stderr won't be enough.
Quoted 76 lines
---
kvm-all.c| 45 +++++++++++++++++++++++++++------------------1 file changed, 27 insertions(+), 18 deletions(-)kvm-all.c +27
-18@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_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; +fprintf (stderr, +"Warning: Number of SMP cpus requested (%d) exceeds " +"recommended cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + + 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 );Signature · 1 line
1.8.1.4
Signature · 1 line
Eduardo
Am 22.08.2013 18:12, schrieb Eduardo Habkost:
Quoted 77 lines · Andrew Jones
Quoted 10 lines
The comment in
kvm_max_vcpus()states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should checkKVM_CAP_NR_VCPUSfor the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.Signed-off-by Andrew Jones <[email protected]>CCing libvir-list. It is probably interesting for libvirt to expose or warn about the recommended VCPU limit somehow, and in this case a simple warning on stderr won't be enough.
Quoted 62 lines
---
kvm-all.c| 45 +++++++++++++++++++++++++++------------------1 file changed, 27 insertions(+), 18 deletions(-)kvm-all.c +19
-18@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_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; +fprintf (stderr, +"Warning: Number of SMP cpus requested (%d) exceeds " +"recommended cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); +
Quoted 8 lines
kvm-all.c int kvm_init(void) · line 1400
Quoted 8 lines
kvm-all.c +8
-0+ 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; + }
Should at least the fatal one use the new error_report()?
Quoted 3 lines
kvm-all.c int kvm_init(void) · line 1403
Quoted 3 lines
kvm-all.c +0
-0} s->vmfd =kvm_ioctl (s,KVM_CREATE_VM ,0 );
I notice that only checks in kvm_init() based on smp_cpus are touched herein. Should we add similar checks to CPU hot-add code and thus possibly move that into some per-vCPU code path?
Regards,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
----- Original Message -----
Quoted 83 lines
Am 22.08.2013 18:12, schrieb Eduardo Habkost:
Quoted 82 lines · Andrew Jones
Quoted 10 lines
The comment in
kvm_max_vcpus()states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should checkKVM_CAP_NR_VCPUSfor the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.Signed-off-by Andrew Jones <[email protected]>CCing libvir-list. It is probably interesting for libvirt to expose or warn about the recommended VCPU limit somehow, and in this case a simple warning on stderr won't be enough.
Quoted 65 lines
---
kvm-all.c| 45 +++++++++++++++++++++++++++------------------1 file changed, 27 insertions(+), 18 deletions(-)kvm-all.c +14
-16@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_vcpus (s);if (smp_cpus > max_vcpus) { - ret = -EINVAL ; - fprintf(stderr, "Number of SMP cpus requested (%d) exceeds maxcpus "
kvm-all.c +7
-2- "supported by KVM (%d)\n", smp_cpus, max_vcpus); - goto err; +fprintf (stderr, +"Warning: Number of SMP cpus requested (%d) exceeds " +"recommended cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + + max_vcpus =kvm_max_vcpus (s); +if (smp_cpus > max_vcpus) {
Quoted 8 lines
Quoted 6 lines
kvm-all.c int kvm_init(void) · line 1400
Quoted 6 lines
kvm-all.c +6
-0+ ret = -EINVAL ; +fprintf (stderr,"Number of SMP cpus requested (%d) exceeds " +"max cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + goto err; + }Should at least the fatal one use the new
error_report()?
So far kvm-all.c doesn't use error_report(). I'm inclined to leave it that way for now, for the scope of this patch anyway. Maybe we should convert all of kvm-all.c at some point though?
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
} s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);I notice that only checks in
kvm_init()based onsmp_cpusare touched herein. Should we add similar checks to CPU hot-add code and thus possibly move that into some per-vCPU code path?
That's a better question for hot-plug folk. Does smp_cpus map to the current number of cpus, or to the number of possible cpus? If it maps to the number of possible cpus, then this is the right place. If the former, then I guess it'll take more thought. I'ved added Igor (still on vacation) to this reply, but regardless I vote we worry about hot-plug limit checking in different patch.
thanks,
drew
Quoted 7 lines
Regards,
Andreas--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Paolo Bonzini
maintainerIl 23/08/2013 13:33, Andrew Jones ha scritto:
Quoted 6 lines
Does
smp_cpusmap to the current
number of cpus, or to the number of possible cpus? If it maps to the number of possible cpus, then this is the right place. If the former, then I guess it'll take more thought. I'ved added Igor (still on vacation) to this reply, but regardless I vote we worry about hot-plug limit checking in different patch.
smp_cpus is the initial number, max_cpus is the number of possible cpus.
Paolo
----- Original Message -----
Quoted 11 lines
Il 23/08/2013 13:33, Andrew Jones ha scritto:
Quoted 7 lines
Does
smp_cpusmap to the current
number of cpus, or to the number of possible cpus? If it maps to the number of possible cpus, then this is the right place. If the former, then I guess it'll take more thought. I'ved added Igor (still on vacation) to this reply,
but regardless I vote we worry about hot-plug limit checking in different patch.
smp_cpusis the initial number,max_cpusis the number of possible cpus.
Yeah, I noticed that this issue is at least partially addressed already with my v2, which incorporates Marcelo's check against the number of hotpluggable cpus (max_cpus).
drew
Paolo Bonzini
maintainerIl 22/08/2013 17:39, Andrew Jones ha scritto:
Quoted 69 lines
The comment in
kvm_max_vcpus()states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should checkKVM_CAP_NR_VCPUSfor the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.Signed-off-by Andrew Jones <[email protected]>--- kvm-all.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)kvm-all.c +17
-18@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_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; + fprintf(stderr, + "Warning: Number of SMP cpus requested (%d) exceeds " + "recommended cpus supported by KVM (%d)\n",
kvm-all.c int kvm_init(void) · line 1400
Quoted 10 lines
kvm-all.c +10
-0+ smp_cpus, max_vcpus); + + 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; + }
You print both error messages when smp_cpus is greater than the max cpus supported; is it intentional?
Apart from this, the concept looks good. However, please over qemu-kvm.git's uq/master branch, where we already have Marcelo's patch to check max_cpus too against kvm_max_vcpus(s).
Thanks,
Paolo
----- Original Message -----
Quoted 76 lines
Il 22/08/2013 17:39, Andrew Jones ha scritto:
Quoted 75 lines
The comment in
kvm_max_vcpus()states that it's using the recommended procedure from the kernel API documentation to get the max number of vcpus that kvm supports. It is, but by always returning the maximum number supported. The maximum number should only be used for development purposes. qemu should checkKVM_CAP_NR_VCPUSfor the recommended number of vcpus. This patch adds a warning if a user specifies a number of cpus between the recommended and max.Signed-off-by Andrew Jones <[email protected]>--- kvm-all.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-)kvm-all.c +14
-16@@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s)return 0 ; } -static int kvm_max_vcpus (KVMState *s) +/* Find number of supported CPUs using the recommended +* procedure from the kernel API documentation to cope with +* older kernels that may be missing capabilities. +*/ +static int kvm_recommended_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 (ret) ? ret :4 ; +} -return 4 ; +static int kvm_max_vcpus (KVMState *s) +{ +int ret; + + ret =kvm_check_extension (s,KVM_CAP_MAX_VCPUS ); +return (ret) ? ret :kvm_recommended_vcpus (s); }int kvm_init (void )@@ -1383,12 +1383,21 @@ int kvm_init(void) goto err; } - max_vcpus =kvm_max_vcpus (s); + max_vcpus =kvm_recommended_vcpus (s);if (smp_cpus > max_vcpus) { - ret = -EINVAL ; - fprintf(stderr, "Number of SMP cpus requested (%d) exceeds maxcpus "
kvm-all.c +8
-2- "supported by KVM (%d)\n", smp_cpus, max_vcpus); - goto err; +fprintf (stderr, +"Warning: Number of SMP cpus requested (%d) exceeds " +"recommended cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + + max_vcpus =kvm_max_vcpus (s); +if (smp_cpus > max_vcpus) { + ret = -EINVAL ;
Quoted 9 lines
kvm-all.c int kvm_init(void) · line 1400
Quoted 5 lines
kvm-all.c +5
-0+fprintf (stderr,"Number of SMP cpus requested (%d) exceeds " +"max cpus supported by KVM (%d)\n" , + smp_cpus, max_vcpus); + goto err; + }You print both error messages when
smp_cpusis greater than the max cpus supported; is it intentional?
Yup. This way we can inform the user not only that they're greater than hard-max, but also what the soft-max is. This allows the user to choose how much lower to adjust when they correct for the hard-max, possibly going down low enough to avoid blowing the soft-max as well.
Quoted 4 lines
Apart from this, the concept looks good. However, please over qemu-kvm.git's uq/master branch, where we already have Marcelo's patch to check
max_cpustoo againstkvm_max_vcpus(s).
OK, will respin on uq/master.
thanks,
drew