From: Simon Kagstrom Subject: Re: [PATCH] 2/2: Fall back to plain Qemu if KVM is not present, report errors from libkvm Date: Tue, 14 Nov 2006 14:39:48 +0100 Message-ID: <87veli87vf.wl%simon.kagstrom@bth.se> References: <20061114072601.GD28027@galon.ev-en.org> <4559834F.80905@qumranet.com> <8764di9y30.wl%simon.kagstrom@bth.se> <45598F42.5090400@qumranet.com> <871wo69uxb.wl%simon.kagstrom@bth.se> <4559AC1F.9080304@qumranet.com> <87y7qe8c43.wl%simon.kagstrom@bth.se> <4559B574.5000000@qumranet.com> <87wt5y89ik.wl%simon.kagstrom@bth.se> <4559C393.70001@qumranet.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: KVM , Baruch Even Return-path: To: Avi Kivity In-Reply-To: <4559C393.70001-atKUWr5tajBWk0Htik3J/w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org Errors-To: kvm-devel-bounces-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org List-Id: kvm.vger.kernel.org At Tue, 14 Nov 2006 15:24:35 +0200, Avi Kivity wrote: > > Simon Kagstrom wrote: > > diff -u ../orig/kvm-2/qemu/vl.c qemu/vl.c > > --- ../orig/kvm-2/qemu/vl.c 2006-11-05 10:18:52.000000000 +0100 > > +++ qemu/vl.c 2006-11-14 13:56:32.000000000 +0100 > > @@ -5706,6 +5706,10 @@ > > > > nb_nics = 0; > > /* default mac address of the first network interface */ > > +#if USE_KVM > > + if (kvm_qemu_init() < 0) > > + kvm_allowed = 0; > > +#endif > > > > Doesn't this bit will initialize kvm even if the user specified -no-kvm? Yes. Maybe I misunderstood you, but this is how I understood your comments. Sorry for spamming the list with patches. I'll send yet another one. This will check and possibly disable KVM after the command-line options have been parsed. If -no-kvm has been given, nothing will happen. Hopefully this will be the final patch! :-) // Simon diff -u ../orig/kvm-2/qemu/qemu-kvm.c qemu/qemu-kvm.c --- ../orig/kvm-2/qemu/qemu-kvm.c 2006-11-05 10:18:52.000000000 +0100 +++ qemu/qemu-kvm.c 2006-11-14 13:56:35.000000000 +0100 @@ -450,10 +450,30 @@ .io_window = kvm_io_window, }; -void kvm_qemu_init() +int kvm_qemu_init() { + /* Try to initialize kvm */ kvm_context = kvm_init(&qemu_kvm_ops, saved_env); - kvm_create(kvm_context, phys_ram_size, (void**)&phys_ram_base); + if (!kvm_context) { + return -1; + } + + return 0; +} + +int kvm_qemu_create_context(void) +{ + if (kvm_create(kvm_context, phys_ram_size, (void**)&phys_ram_base) < 0) { + kvm_qemu_destroy(); + return -1; + } + + return 0; +} + +void kvm_qemu_destroy(void) +{ + kvm_finalize(kvm_context); } int kvm_update_debugger(CPUState *env) diff -u ../orig/kvm-2/qemu/qemu-kvm.h qemu/qemu-kvm.h --- ../orig/kvm-2/qemu/qemu-kvm.h 2006-10-16 11:01:02.000000000 +0200 +++ qemu/qemu-kvm.h 2006-11-14 13:55:56.000000000 +0100 @@ -3,7 +3,9 @@ #include "kvmctl.h" -void kvm_qemu_init(void); +int kvm_qemu_init(void); +int kvm_qemu_create_context(void); +void kvm_qemu_destroy(void); void kvm_load_registers(CPUState *env); int kvm_cpu_exec(CPUState *env); int kvm_update_debugger(CPUState *env); diff -u ../orig/kvm-2/qemu/vl.c qemu/vl.c --- ../orig/kvm-2/qemu/vl.c 2006-11-05 10:18:52.000000000 +0100 +++ qemu/vl.c 2006-11-14 14:34:18.000000000 +0100 @@ -6054,6 +6054,15 @@ } } +#if USE_KVM + if (kvm_allowed) { + if (kvm_qemu_init() < 0) { + fprintf(stderr, "Could not initialize KVM, will disable KVM support\n"); + kvm_allowed = 0; + } + } +#endif + #ifdef USE_KQEMU if (smp_cpus > 1) kqemu_allowed = 0; @@ -6099,11 +6108,15 @@ } /* init the memory */ -#if USE_KVM phys_ram_size = ram_size + vga_ram_size + bios_size; +#if USE_KVM + /* Initialize kvm */ if (kvm_allowed) { phys_ram_size += KVM_EXTRA_PAGES * 4096; - kvm_qemu_init(); + if (kvm_qemu_create_context() < 0) { + fprintf(stderr, "Could not create KVM context\n"); + exit(1); + } } else { phys_ram_base = qemu_vmalloc(phys_ram_size); if (!phys_ram_base) { @@ -6112,7 +6125,6 @@ } } #else - phys_ram_size = ram_size + vga_ram_size + bios_size; phys_ram_base = qemu_vmalloc(phys_ram_size); if (!phys_ram_base) { fprintf(stderr, "Could not allocate physical memory\n"); ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642