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); } } -- 1.6.6.1