From patchwork Tue Jul 31 10:14:23 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dunrong huang X-Patchwork-Id: 174193 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 83B2B2C0080 for ; Tue, 31 Jul 2012 20:15:21 +1000 (EST) Received: from localhost ([::1]:40697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sw9Tz-0006Ow-Hm for incoming@patchwork.ozlabs.org; Tue, 31 Jul 2012 06:15:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36302) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sw9Tn-0006NN-RN for qemu-devel@nongnu.org; Tue, 31 Jul 2012 06:15:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sw9Tj-0007Yp-Mc for qemu-devel@nongnu.org; Tue, 31 Jul 2012 06:15:07 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:64099) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sw9Tj-0007Xg-GE for qemu-devel@nongnu.org; Tue, 31 Jul 2012 06:15:03 -0400 Received: by pbbro12 with SMTP id ro12so10894422pbb.4 for ; Tue, 31 Jul 2012 03:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=q2ehaytQM3JT7sACVdFw5w40UtXWJ6m3wbuJ8DSNlHA=; b=ku+YzMtwdugC2a8DB3nLjPRGV8LuoHm++u+1z1DjKpiayjnJfSNKvkfroEA7s+y+Sw 281Y3OeiJb74mIYkeWmKL3Lx1mFf80dJXWGZbqfCk9fa8ox4GC7pvwCD9hZPqiu0sFKB alrW7l9+xLx7wA1m2UZPDgSayMPDsk78uWB+oi7pRKIqOLJToEdUItzsa/nFzI2OpI05 SrGdI2bT49OrlPZCk4I2qCOWpTqM59bX3GKz5oMUsXYcJyE1AMGtMZvZOdGrbx/sAzp/ xyc028J+P9ejPGbJstcL58ywEBnoKAzGjm4DYFKVn7s9gjLh4WpQ4ISLwFNaEJdpTdky Un2Q== Received: by 10.68.223.138 with SMTP id qu10mr43274675pbc.50.1343729702590; Tue, 31 Jul 2012 03:15:02 -0700 (PDT) Received: from localhost.localdomain ([114.249.88.183]) by mx.google.com with ESMTPS id pj10sm953pbb.46.2012.07.31.03.14.55 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 03:15:01 -0700 (PDT) From: riegamaths@gmail.com To: qemu-devel Date: Tue, 31 Jul 2012 18:14:23 +0800 Message-Id: <1343729663-20527-1-git-send-email-riegamaths@gmail.com> X-Mailer: git-send-email 1.7.8.6 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: Marcelo Tosatti , Dunrong Huang , Stefan Hajnoczi , kvm@vger.kernel.org, Avi Kivity Subject: [Qemu-devel] [PATCH v2] kvm: Check if smp_cpus exceeds max cpus supported by kvm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Dunrong Huang 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 --- v1 -> v2: * Fix indentation kvm-all.c | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) 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