From patchwork Fri Apr 2 15:01:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 49294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 97373B7080 for ; Sat, 3 Apr 2010 02:03:34 +1100 (EST) Received: from localhost ([127.0.0.1]:47396 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NxiP2-0007PR-J3 for incoming@patchwork.ozlabs.org; Fri, 02 Apr 2010 11:03:20 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NxiNF-0007HD-BK for qemu-devel@nongnu.org; Fri, 02 Apr 2010 11:01:29 -0400 Received: from [140.186.70.92] (port=52700 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NxiNB-0007CM-24 for qemu-devel@nongnu.org; Fri, 02 Apr 2010 11:01:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NxiN8-0004ap-Fn for qemu-devel@nongnu.org; Fri, 02 Apr 2010 11:01:24 -0400 Received: from mail-ew0-f227.google.com ([209.85.219.227]:45948) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NxiN8-0004a7-6U for qemu-devel@nongnu.org; Fri, 02 Apr 2010 11:01:22 -0400 Received: by ewy27 with SMTP id 27so613660ewy.10 for ; Fri, 02 Apr 2010 08:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type; bh=/mcbzqV4En5mb7rMpNiz81Ycpu9h59dOoVt06uDle2c=; b=Y+Y5oJL91wrSYGOrK8JnDoUEeE5tZHmtdMqLmKDYMP9Br6aYltJGrl24owQikl0acS eT+vOLjlmYLDNl++/YwXoYpeby5tFFRag1eMSLZCBOH/CLXR0To/dbr1cEVGvdpd68eH 4O0dySsLFcEAKuNCTYKQPXqgEpeL32f5SSO9Q= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type; b=YxRnMoYwsAerEAseoteU7yluAs0A9gipqq31yHfuIQqdsZE5juE22+WPYfwLD4Ym+a o3QdgExH4B8rQNFzC1VviqUTntbtMfJhjIXEEZSNmaCHB9TB510K0BGeiMCHGXBKp98R IeHGy9Kr4DHxF7KFS4u3TzzexMR2g6FPrU8YI= Received: by 10.213.48.12 with SMTP id p12mr229472ebf.86.1270220481067; Fri, 02 Apr 2010 08:01:21 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-197-68.ip51.fastwebnet.it [93.34.197.68]) by mx.google.com with ESMTPS id 14sm5045694ewy.10.2010.04.02.08.01.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 02 Apr 2010 08:01:20 -0700 (PDT) Message-ID: <4BB606BE.9000508@redhat.com> Date: Fri, 02 Apr 2010 17:01:18 +0200 From: Paolo Bonzini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.8) Gecko/20100301 Fedora/3.0.3-1.fc12 Lightning/1.0b2pre Thunderbird/3.0.3 MIME-Version: 1.0 To: Blue Swirl References: <4BB4FED5.2080508@codemonkey.ws> In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel Subject: [Qemu-devel] Re: [PATCH 1/2] Move KVM init to arch_init.c, compile vl.c once X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On 04/01/2010 10:27 PM, Blue Swirl wrote: > It will not be safe to use kvm_enabled() in vl.c, so there needs to be > a target dependent helper. The call to kvm_init could remain in vl.c, > likewise it's not strictly needed to move kvm_allowed to arch_init.c. Not really, because kvm_allowed _can_ be used from once-compiled files. The attached patch makes kvm-all.c be compiled always, even if !CONFIG_KVM; functions that require kvm are almost always omitted for now (so checking kvm_enabled() is required to call them). However, kvm_init is stubbed so that vl.c can call it. In the future we could add more stubbing and ultimately do this unconditionally: #define kvm_enabled() kvm_allowed With this patch vl.c can already be compiled once, but I did not include it because it would conflict with my balloon.c series; I'm doing enough rebasing these days. Also, qemu-kvm is a bit behind qemu and all these patches are nightmares for the merges, so it's better IMO if things are left to calm down a bit. > They just caused problems with the poisoning check in patch 2/2. Poisoning kvm_enabled is right, but poisoning kvm_allowed is overkill. Paolo From e9bd21893633365567b7c0d468a9971ab02e46f0 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 2 Apr 2010 09:29:54 +0200 Subject: [PATCH] provide a stub version of kvm-all.c if !CONFIG_KVM This allows limited use of kvm functions (which will return ENOSYS) even in once-compiled modules. The patch also improves a bit the error messages for KVM initialization. Signed-off-by: Paolo Bonzini --- Makefile.target | 4 ++-- kvm-all.c | 16 ++++++++++++++-- kvm.h | 4 +++- vl.c | 16 +++++++--------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Makefile.target b/Makefile.target index 167fc8d..3943de1 100644 --- a/Makefile.target +++ b/Makefile.target @@ -168,8 +168,8 @@ obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-b obj-y += event_notifier.o obj-y += vhost_net.o obj-$(CONFIG_VHOST_NET) += vhost.o -obj-y += rwhandler.o -obj-$(CONFIG_KVM) += kvm.o kvm-all.o +obj-y += rwhandler.o kvm-all.o +obj-$(CONFIG_KVM) += kvm.o LIBS+=-lz QEMU_CFLAGS += $(VNC_TLS_CFLAGS) diff --git a/kvm-all.c b/kvm-all.c index 7aa5e57..53f58a6 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -13,14 +13,16 @@ * */ +#include "qemu-common.h" #include #include #include #include +#ifdef CONFIG_KVM #include +#endif -#include "qemu-common.h" #include "qemu-barrier.h" #include "sysemu.h" #include "hw/hw.h" @@ -73,6 +75,7 @@ struct KVMState static KVMState *kvm_state; +#ifdef CONFIG_KVM static KVMSlot *kvm_alloc_slot(KVMState *s) { int i; @@ -282,7 +285,7 @@ static int kvm_set_migration_log(int enable) return 0; } -static int test_le_bit(unsigned long nr, unsigned char *addr) +static inline int test_le_bit(unsigned long nr, unsigned char *addr) { return (addr[nr >> 3] >> (nr & 7)) & 1; } @@ -561,9 +564,11 @@ static CPUPhysMemoryClient kvm_cpu_phys_memory_client = { .sync_dirty_bitmap = kvm_client_sync_dirty_bitmap, .migration_log = kvm_client_migration_log, }; +#endif int kvm_init(int smp_cpus) { +#ifdef CONFIG_KVM static const char upgrade_note[] = "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" "(see http://sourceforge.net/projects/kvm).\n"; @@ -683,8 +688,12 @@ err: qemu_free(s); return ret; +#else + return -ENOSYS; +#endif } +#ifdef CONFIG_KVM static int kvm_handle_io(uint16_t port, void *data, int direction, int size, uint32_t count) { @@ -866,6 +875,7 @@ int kvm_cpu_exec(CPUState *env) return ret; } +#endif int kvm_ioctl(KVMState *s, int type, ...) { @@ -1139,6 +1149,7 @@ void kvm_remove_all_breakpoints(CPUState *current_env) } #endif /* !KVM_CAP_SET_GUEST_DEBUG */ +#ifdef CONFIG_KVM int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset) { struct kvm_signal_mask *sigmask; @@ -1156,6 +1167,7 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset) return r; } +#endif #ifdef KVM_IOEVENTFD int kvm_set_ioeventfd_pio_word(int fd, uint16_t addr, uint16_t val, bool assign) diff --git a/kvm.h b/kvm.h index 1e5be27..2477cfd 100644 --- a/kvm.h +++ b/kvm.h @@ -18,13 +18,15 @@ #include #include "config-host.h" #include "qemu-queue.h" +#include "cpu-common.h" #ifdef CONFIG_KVM #include #endif -#ifdef CONFIG_KVM extern int kvm_allowed; + +#ifdef CONFIG_KVM #define kvm_enabled() (kvm_allowed) #else #define kvm_enabled() (0) diff --git a/vl.c b/vl.c index 6768cf1..9fe4682 100644 --- a/vl.c +++ b/vl.c @@ -3235,10 +3235,6 @@ int main(int argc, char **argv, char **envp) do_smbios_option(optarg); break; case QEMU_OPTION_enable_kvm: - if (!(kvm_available())) { - printf("Option %s not supported for this target\n", popt->name); - exit(1); - } kvm_allowed = 1; break; case QEMU_OPTION_usb: @@ -3585,12 +3581,14 @@ int main(int argc, char **argv, char **envp) exit(1); } - if (kvm_enabled()) { - int ret; - - ret = kvm_init(smp_cpus); + if (kvm_allowed) { + int ret = kvm_init(smp_cpus); if (ret < 0) { - fprintf(stderr, "failed to initialize KVM\n"); + if (!kvm_available()) { + printf("KVM not supported for this target\n"); + } else { + fprintf(stderr, "failed to initialize KVM: %s\n", strerror(-ret)); + } exit(1); } }