Skip to contentSkip to conversation

dont exit() from libkvm

PATCH Applied muli-7z/[email protected] 3 participants 10 messages Feb 6, 2007 – Feb 7, 2007 1 message not in the archive KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dont exit() from libkvm

This patchset removes calls to exit() from libkvm to make it more friendly to callers. qemu is updated to exit() itself if kvm_run() returns.

Tested by booting WinXP on x86-64.

Cheers,
Muli

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

A message that is not in the archive (sent off-list or not yet received): patchbomb.1170800271-WD1JZD8MxeCTrf4lBMg6DdBPR1lH4CV8@public.gmane.org

#2 lore raw

PATCH 1/1 dont exit from kvm_get_dirty_pages on failure

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170798195 -7200
# Node ID 2328694370e14268564468e4c872fdbf30f6c3d6
# Parent 74c55612f99d478ff219758822778aac910e85f4
dont exit from kvm_get_dirty_pages on failure

qemu/hw/vga.c +7 -3
diff -r 74c55612f99d -r 2328694370e1 qemu/hw/vga.c
@@ -1396,9 +1396,13 @@ static void vga_draw_graphic(VGAState *s
     /* HACK ALERT */
 #define BITMAP_SIZE ((8*1024*1024) / 4096 / 8 / sizeof(long))
     unsigned long bitmap[BITMAP_SIZE];
-
-    if (kvm_allowed)
-	    kvm_get_dirty_pages(kvm_context, 1, &bitmap);
+    int r;
+
+    if (kvm_allowed) {
+	    r = kvm_get_dirty_pages(kvm_context, 1, &bitmap);
+	    if (r < 0)
+		    fprintf(stderr, "kvm: get_dirty_pages returned %d\n", r);
+    }
 #endif
 
     full_update |= update_basic_params(s);
user/kvmctl.c +2 -2
diff -r 74c55612f99d -r 2328694370e1 user/kvmctl.c
@@ -205,7 +205,7 @@ void kvm_destroy_phys_mem(kvm_context_t 
 }
 
 
-void kvm_get_dirty_pages(kvm_context_t kvm, int slot, void *buf)
+int kvm_get_dirty_pages(kvm_context_t kvm, int slot, void *buf)
 {
 	int r;
 	struct kvm_dirty_log log = {
@@ -216,7 +216,7 @@ void kvm_get_dirty_pages(kvm_context_t k
 
 	r = ioctl(kvm->fd, KVM_GET_DIRTY_LOG, &log);
 	if (r == -1)
-		exit(1);
+		return -errno;
 }
 
 static int more_io(struct kvm_run *run, int first_time)
user/kvmctl.h +1 -1
diff -r 74c55612f99d -r 2328694370e1 user/kvmctl.h
@@ -248,6 +248,6 @@ void *kvm_create_phys_mem(kvm_context_t,
 			  unsigned long len, int slot, int log, int writable);
 void kvm_destroy_phys_mem(kvm_context_t, unsigned long phys_start, 
 			  unsigned long len);
-void kvm_get_dirty_pages(kvm_context_t, int slot, void *buf);
+int kvm_get_dirty_pages(kvm_context_t, int slot, void *buf);
 
 #endif

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

#3 lore raw

PATCH 1/1 dont exit on translate() failure in handle_io

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170798403 -7200
# Node ID f49e30e2c4db4306d7d50193cac9bc87826c1f70
# Parent 2328694370e14268564468e4c872fdbf30f6c3d6
dont exit on translate() failure in handle_io

instead return and cause kvm_run to return

user/kvmctl.c +1 -1
diff -r 2328694370e1 -r f49e30e2c4db user/kvmctl.c
@@ -262,7 +262,7 @@ static int handle_io(kvm_context_t kvm, 
 			if (r) {
 				fprintf(stderr, "failed translating I/O address %x\n",
 					run->io.address);
-				exit(1);
+				return r;
 			}
 		}
 

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

#4 lore raw

PATCH 1/1 dont exit on bad IO sizes or directions

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170798768 -7200
# Node ID 3b02d537956d3df608c24be8cbba0f2985bf2705
# Parent f49e30e2c4db4306d7d50193cac9bc87826c1f70
dont exit on bad IO sizes or directions

Also slightly improve the debug messages while I was there

user/kvmctl.c +6 -6
diff -r f49e30e2c4db -r 3b02d537956d user/kvmctl.c
@@ -288,8 +288,8 @@ static int handle_io(kvm_context_t kvm, 
 				break;
 			}
 			default:
-				fprintf(stderr, "bad I/O size\n");
-				exit(1);
+				fprintf(stderr, "bad I/O size %d\n", run->io.size);
+				return -EMSGSIZE;
 			}
 			break;
 		}
@@ -308,13 +308,13 @@ static int handle_io(kvm_context_t kvm, 
 						     *(uint32_t *)value_addr);
 				break;
 			default:
-				fprintf(stderr, "bad I/O size\n");
-				exit(1);
+				fprintf(stderr, "bad I/O size %d\n", run->io.size);
+				return -EMSGSIZE;
 			}
 			break;
 		default:
-			fprintf(stderr, "bad I/O size\n");
-			exit(1);
+			fprintf(stderr, "bad I/O direction %d\n", run->io.direction);
+			return -EPROTO;
 		}
 		if (run->io.string) {
 			run->io.address += delta;

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

#5 lore raw

PATCH 1/1 dont exit if KVM_GET_REGS fails in kvm_show_regs

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170798906 -7200
# Node ID d70ecd2477a2102c4f47435be0c40ef3fade6500
# Parent 3b02d537956d3df608c24be8cbba0f2985bf2705
dont exit if KVM_GET_REGS fails in kvm_show_regs

user/kvmctl.c +1 -1
diff -r 3b02d537956d -r d70ecd2477a2 user/kvmctl.c
@@ -457,7 +457,7 @@ void kvm_show_regs(kvm_context_t kvm, in
 	r = ioctl(fd, KVM_GET_REGS, &regs);
 	if (r == -1) {
 		perror("KVM_GET_REGS");
-		exit(1);
+		return;
 	}
 	fprintf(stderr,
 		"rax %016llx rbx %016llx rcx %016llx rdx %016llx\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

#6 lore raw

PATCH 1/1 dont exit if ioctl(KVM_RUN) fails

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170799111 -7200
# Node ID 41e4dfc33562ba2787edad1343f1c4705ba6e9ba
# Parent d70ecd2477a2102c4f47435be0c40ef3fade6500
dont exit if ioctl(KVM_RUN) fails

instead return -errno to the caller of kvm_run

user/kvmctl.c +2 -1
diff -r d70ecd2477a2 -r 41e4dfc33562 user/kvmctl.c
@@ -579,8 +579,9 @@ again:
 	kvm_run.emulated = 0;
 	kvm_run.mmio_completed = 0;
 	if (r == -1 && errno != EINTR) {
+		r = -errno;
 		printf("kvm_run: %m\n");
-		exit(1);
+		return r;
 	}
 	if (r == -1) {
 		r = handle_io_window(kvm, &kvm_run);

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

#7 lore raw

PATCH 1/1 dont exit if we get KVM_EXIT_TYPE_FAIL_ENTRY

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170799295 -7200
# Node ID 304d92f7ab0cc3ead93f0cde06205a9c58bac640
# Parent 41e4dfc33562ba2787edad1343f1c4705ba6e9ba
dont exit if we get KVM_EXIT_TYPE_FAIL_ENTRY

instead return -ENOEXEC and let the caller worry about it

user/kvmctl.c +1 -1
diff -r 41e4dfc33562 -r 304d92f7ab0c user/kvmctl.c
@@ -591,7 +591,7 @@ again:
 	case KVM_EXIT_TYPE_FAIL_ENTRY:
 		fprintf(stderr, "kvm_run: failed entry, reason %u\n", 
 			kvm_run.exit_reason & 0xffff);
-		exit(1);
+		return -ENOEXEC;
 		break;
 	case KVM_EXIT_TYPE_VM_EXIT:
 		switch (kvm_run.exit_reason) {

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

#8 lore raw

PATCH 1/1 teach qemu to handle kvm_run failures

In reply to a message not in the archive

# HG changeset patch
# User Muli Ben-Yehuda <muli-7z/[email protected]> # Date 1170799532 -7200
# Node ID 17f2aab24892d4db7d30a2740765ebf55600e3e2
# Parent 304d92f7ab0cc3ead93f0cde06205a9c58bac640
teach qemu to handle kvm_run failures

... by exiting.

qemu/qemu-kvm.c +6 -1
diff -r 304d92f7ab0c -r 17f2aab24892 qemu/qemu-kvm.c
@@ -423,6 +423,7 @@ void kvm_save_registers(CPUState *env)
 
 int kvm_cpu_exec(CPUState *env)
 {
+    int r;
     int pending = (!env->ready_for_interrupt_injection ||
                    ((env->interrupt_request & CPU_INTERRUPT_HARD) &&
 		   (env->eflags & IF_MASK)));
@@ -437,7 +438,11 @@ int kvm_cpu_exec(CPUState *env)
     if (!saved_env[0])
 	saved_env[0] = env;
 
-    kvm_run(kvm_context, 0);
+    r = kvm_run(kvm_context, 0);
+    if (r < 0) {
+        printf("kvm_run returned %d\n", r);
+        exit(1);
+    }
 
     return 0;
 }

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

#9 lore raw
In reply to a message not in the archive
Quoted 4 lines · muli-7z/[email protected] wrote:

This patchset removes calls to exit() from libkvm to make it more friendly to callers. qemu is updated to exit() itself if kvm_run() returns.

Good stuff!

Regards,

Anthony Liguori

Quoted 5 lines

Tested by booting WinXP on x86-64.

Cheers,
Muli

Quoted 11 lines

-------------------------------------------------------------------------
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
_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

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

Applied
#10 lore raw
In reply to a message not in the archive
Quoted 7 lines · muli-7z/[email protected] wrote:

This patchset removes calls to exit() from libkvm to make it more friendly to callers. qemu is updated to exit() itself if kvm_run() returns.

Tested by booting WinXP on x86-64.

Applied, thanks.

Note there's no need for such fine patch granularity, especially in libkvm/qemu.

Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


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