From patchwork Thu Aug 22 15:39:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 2848305 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 669F9BF546 for ; Thu, 22 Aug 2013 15:39:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4FBE020504 for ; Thu, 22 Aug 2013 15:39:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 09E18203A3 for ; Thu, 22 Aug 2013 15:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753526Ab3HVPjg (ORCPT ); Thu, 22 Aug 2013 11:39:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:63843 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752280Ab3HVPjg (ORCPT ); Thu, 22 Aug 2013 11:39:36 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r7MFdYL7018348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 22 Aug 2013 11:39:34 -0400 Received: from hawk.usersys.redhat.com.com (dhcp-1-112.brq.redhat.com [10.34.1.112]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r7MFdWWN027735; Thu, 22 Aug 2013 11:39:32 -0400 From: Andrew Jones To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, pbonzini@redhat.com, gleb@redhat.com, mtosatti@redhat.com, ehabkost@redhat.com Subject: [PATCH] kvm: warn if num cpus is greater than num recommended Date: Thu, 22 Aug 2013 17:39:28 +0200 Message-Id: <1377185968-13129-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Andrew Jones --- kvm-all.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 716860f617455..9092e13ae60ea 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -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);