qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] kqemu.c should check return value for ioctl(KQEMU_EXEC)
@ 2008-06-17 12:07 Juergen Keil
  0 siblings, 0 replies; only message in thread
From: Juergen Keil @ 2008-06-17 12:07 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: TEXT/plain, Size: 1530 bytes --]


When kqemu is enabled, the ioctl(KQEMU_EXEC) could fail for several 
reasons (e.g. with Linux kqemu-1.4.0pre1 it can fail with EIO or FAULT;
and on OpenSolaris I just have a case where it's failing with EINVAL).

Problem is that in qemu's file kqemu.c function kqemu_cpu_exec() the
return value from the ioctl(KQEMU_EXEC) is ignored and the code continues
with the uninitialized kenv->retval.

Depending on the uninitialized kenv->retval, you may or may not get 
a Qemu abort with a register dump and an "Unsupported return value"
error message. And there is no indication that the root cause was a
failed ioctl. Like this:

% qemu -m 512 -localtime -hda /files2/qemu/sol10u4.img -cdrom 
/files2/media/sol-10-u4-ga-x86-dvd.iso -boot d
EAX=00000000 EBX=00000000 ECX=00000000 EDX=00000000
ESI=00000000 EDI=00000000 EBP=00000000 ESP=08047f58
EIP=d27cb7b6 EFL=00000202 [-------] CPL=3 II=0 A20=1 SMM=0 HLT=0
ES =0173 00000000 ffffffff 00cff300
CS =016b 00000000 ffffffff 00cffb00
SS =0173 00000000 ffffffff 00cff300
DS =0173 00000000 ffffffff 00cff300
FS =0000 00000000 00000000 00000000
GS =01c3 d27fb400 ffffffff d2cff37f
LDT=0000 00000000 00000000 00008200
TR =0150 fec21a50 00000067 00008900
GDT=     fec01000 000002cf
IDT=     fec20da0 000007ff
CR0=8005003b CR2=00000000 CR3=1e0d8000 CR4=00000698
Unsupported return value: 0xfffffd7f


kqemu_cpu_exec() should check the return value from
ioctl(KQEMU_EXEC) and report some error when the ioctl
failed.  And it should stop execution in some deterministic
way.

Patch is attached.

[-- Attachment #2: kqemu_exec_ioctl_rval.patch --]
[-- Type: TEXT/plain, Size: 568 bytes --]

Index: kqemu.c
===================================================================
--- kqemu.c	(revision 4734)
+++ kqemu.c	(working copy)
@@ -771,8 +771,12 @@
         ret = -1;
     }
 #else
-    ioctl(kqemu_fd, KQEMU_EXEC, kenv);
-    ret = kenv->retval;
+    if (ioctl(kqemu_fd, KQEMU_EXEC, kenv) < 0) {
+        fprintf(stderr, "Error while running code in QEMU acceleration layer: %s\n", strerror(errno));
+        ret = -1;
+    } else {
+        ret = kenv->retval;
+    }
 #endif
     if (env->cpuid_features & CPUID_FXSR)
         save_native_fp_fxsave(env);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-17 12:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-17 12:07 [Qemu-devel] [PATCH] kqemu.c should check return value for ioctl(KQEMU_EXEC) Juergen Keil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).