[PATCH] 2/2: Fall back to plain Qemu if KVM is not present, report errors from libkvm

Simon Kagstrom
2006-11-14T10:36:32Z

[-- Attachment #1: Type: text/plain, Size: 193 bytes --]

This patch implements fall-back to plain Qemu if KVM is not
present. Some logic has been moved into kvm_qemu_init.

Signed-off-by: Simon Kagstrom <simon.kagstrom-6Uc+yI3S9P8@public.gmane.org>

[-- Attachment #2: qemu-kvm-start-transparent.patch --]
[-- Type: application/octet-stream, Size: 2651 bytes --]

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 11:04:19.000000000 +0100
@@ -450,10 +450,20 @@
.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;
+ }
+ phys_ram_size += KVM_EXTRA_PAGES * 4096;
+ if (kvm_create(kvm_context, phys_ram_size, (void**)&phys_ram_base) < 0) {
+ kvm_finalize(kvm_context);
+ return -1;
+ }
+
+ return 0;
}

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 10:00:48.000000000 +0100
@@ -3,7 +3,9 @@

#include "kvmctl.h"

-void kvm_qemu_init(void);
+#define KVM_EXTRA_PAGES 3
+
+int kvm_qemu_init(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 11:07:17.000000000 +0100
@@ -6099,20 +6099,24 @@
}

/* 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();
- } else {
- phys_ram_base = qemu_vmalloc(phys_ram_size);
- if (!phys_ram_base) {
- fprintf(stderr, "Could not allocate physical memory\n");
- exit(1);
- }
+ if (kvm_qemu_init() < 0) {
+ fprintf(stderr, "Could not initialize KVM\n");
+ kvm_allowed = 0;
+ }
+ }
+ /* Fall back to normal qemu if KVM fails */
+ if (!kvm_allowed) {
+ phys_ram_base = qemu_vmalloc(phys_ram_size);
+ if (!phys_ram_base) {
+ fprintf(stderr, "Could not allocate physical memory\n");
+ exit(1);
+ }
}
#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");
diff -u ../orig/kvm-2/qemu/vl.h qemu/vl.h
--- ../orig/kvm-2/qemu/vl.h 2006-11-05 10:18:52.000000000 +0100
+++ qemu/vl.h 2006-11-14 09:48:31.000000000 +0100
@@ -162,10 +162,6 @@
#define BIOS_SIZE ((256 + 64) * 1024)
#endif

-#if USE_KVM
-#define KVM_EXTRA_PAGES 3
-#endif
-
/* keyboard/mouse support */

#define MOUSE_EVENT_LBUTTON 0x01

[-- Attachment #3: Type: text/plain, Size: 373 bytes --]

-------------------------------------------------------------------------
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

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org