On Fri, Jan 21, 2011 at 12:18:28PM +0100, Stefan Sperling wrote: > It would be interesting to know if this helps others who have seen qemu crash.
Well it did eventually crash again, but with a nonesense trace this time. Meanwhile I've been looking at some of the signal handlers and there are quite a few that naively use non-volatile global variables and also linked lists. Below is what I'm running with now hoping it will help. But I didn't try to fix the ones that traverse linked lists (they are in the shutdown and gdbstub code paths). Putting this here in case more people want to help testing to see if this really makes a difference. This one also applies to -current, thanks for the hint Stuart. Maybe compiling without optimisation will help? Did anyone ever try that? Index: Makefile =================================================================== RCS file: /cvs/ports/emulators/qemu/Makefile,v retrieving revision 1.60 diff -u -p -r1.60 Makefile --- Makefile 19 Jan 2011 16:22:31 -0000 1.60 +++ Makefile 21 Jan 2011 17:24:45 -0000 @@ -6,7 +6,7 @@ ONLY_FOR_ARCHS = i386 amd64 sparc64 COMMENT = multi system emulator DISTNAME = qemu-0.13.0 -REVISION = 0 +REVISION = 1 CATEGORIES = emulators HOMEPAGE = http://www.qemu.org/ Index: patches/patch-cpu-all_h =================================================================== RCS file: patches/patch-cpu-all_h diff -N patches/patch-cpu-all_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-cpu-all_h 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- cpu-all.h.orig Fri Jan 21 17:49:27 2011 ++++ cpu-all.h Fri Jan 21 17:49:43 2011 +@@ -775,7 +775,7 @@ void cpu_dump_statistics (CPUState *env, FILE *f, + void QEMU_NORETURN cpu_abort(CPUState *env, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + extern CPUState *first_cpu; +-extern CPUState *cpu_single_env; ++extern volatile CPUState *cpu_single_env; + + #define CPU_INTERRUPT_HARD 0x02 /* hardware interrupt pending */ + #define CPU_INTERRUPT_EXITTB 0x04 /* exit the current TB (use for x86 a20 case) */ Index: patches/patch-cpus_c =================================================================== RCS file: patches/patch-cpus_c diff -N patches/patch-cpus_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-cpus_c 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- cpus.c.orig Fri Jan 21 10:24:52 2011 ++++ cpus.c Fri Jan 21 10:26:29 2011 +@@ -149,7 +149,7 @@ static void cpu_debug_handler(CPUState *env) + } + + #ifndef _WIN32 +-static int io_thread_fd = -1; ++static volatile sig_atomic_t io_thread_fd = -1; + + static void qemu_event_increment(void) + { Index: patches/patch-exec_c =================================================================== RCS file: /cvs/ports/emulators/qemu/patches/patch-exec_c,v retrieving revision 1.9 diff -u -p -r1.9 patch-exec_c --- patches/patch-exec_c 22 Nov 2010 11:32:01 -0000 1.9 +++ patches/patch-exec_c 21 Jan 2011 17:24:09 -0000 @@ -1,6 +1,20 @@ $OpenBSD: patch-exec_c,v 1.9 2010/11/22 11:32:01 fgsch Exp $ ---- exec.c.orig Fri Oct 15 21:56:09 2010 -+++ exec.c Thu Nov 18 09:21:58 2010 +--- exec.c.orig Fri Oct 15 22:56:09 2010 ++++ exec.c Fri Jan 21 17:19:20 2011 +@@ -119,11 +119,11 @@ RAMList ram_list = { .blocks = QLIST_HEAD_INITIALIZER( + CPUState *first_cpu; + /* current CPU in the current thread. It is only valid inside + cpu_exec() */ +-CPUState *cpu_single_env; ++volatile CPUState *cpu_single_env; + /* 0 = Do not count executed instructions. + 1 = Precise instruction counting. + 2 = Adaptive rate instruction counting. */ +-int use_icount = 0; ++volatile sig_atomic_t use_icount = 0; + /* Current instruction counter. While executing translated code this may + include some instructions that have not yet been executed. */ + int64_t qemu_icount; @@ -524,7 +524,8 @@ static void code_gen_alloc(unsigned long tb_size) exit(1); } Index: patches/patch-posix-aio-compat_c =================================================================== RCS file: patches/patch-posix-aio-compat_c diff -N patches/patch-posix-aio-compat_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-posix-aio-compat_c 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- posix-aio-compat.c.orig Fri Jan 21 10:27:04 2011 ++++ posix-aio-compat.c Fri Jan 21 10:15:20 2011 +@@ -495,7 +495,7 @@ static int posix_aio_flush(void *opaque) + return !!s->first_aio; + } + +-static PosixAioState *posix_aio_state; ++static volatile PosixAioState *posix_aio_state; + + static void aio_signal_handler(int signum) + { Index: patches/patch-qemu-timer_c =================================================================== RCS file: /cvs/ports/emulators/qemu/patches/patch-qemu-timer_c,v retrieving revision 1.1 diff -u -p -r1.1 patch-qemu-timer_c --- patches/patch-qemu-timer_c 22 Nov 2010 11:32:01 -0000 1.1 +++ patches/patch-qemu-timer_c 21 Jan 2011 17:24:09 -0000 @@ -1,6 +1,6 @@ $OpenBSD: patch-qemu-timer_c,v 1.1 2010/11/22 11:32:01 fgsch Exp $ ---- qemu-timer.c.orig Thu Nov 18 09:27:07 2010 -+++ qemu-timer.c Thu Nov 18 09:27:26 2010 +--- qemu-timer.c.orig Fri Oct 15 22:56:09 2010 ++++ qemu-timer.c Fri Jan 21 17:39:06 2011 @@ -108,7 +108,8 @@ static void init_get_clock(void) { use_rt_clock = 0; @@ -21,3 +21,27 @@ $OpenBSD: patch-qemu-timer_c,v 1.1 2010/ if (use_rt_clock) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); +@@ -140,10 +142,10 @@ static int64_t get_clock(void) + /* guest cycle counter */ + + typedef struct TimersState { +- int64_t cpu_ticks_prev; +- int64_t cpu_ticks_offset; +- int64_t cpu_clock_offset; +- int32_t cpu_ticks_enabled; ++ volatile int64_t cpu_ticks_prev; ++ volatile int64_t cpu_ticks_offset; ++ volatile int64_t cpu_clock_offset; ++ volatile sig_atomic_t cpu_ticks_enabled; + int64_t dummy; + } TimersState; + +@@ -251,7 +253,7 @@ struct qemu_alarm_timer { + char pending; + }; + +-static struct qemu_alarm_timer *alarm_timer; ++static volatile struct qemu_alarm_timer *alarm_timer; + + int qemu_alarm_pending(void) + { Index: patches/patch-qemu-timer_h =================================================================== RCS file: patches/patch-qemu-timer_h diff -N patches/patch-qemu-timer_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-qemu-timer_h 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- qemu-timer.h.orig Fri Jan 21 17:18:01 2011 ++++ qemu-timer.h Fri Jan 21 17:18:16 2011 +@@ -74,7 +74,7 @@ void qemu_get_ptimer(QEMUFile *f, ptimer_state *s); + /* icount */ + int64_t qemu_icount_round(int64_t count); + extern int64_t qemu_icount; +-extern int use_icount; ++extern volatile sig_atomic_t use_icount; + extern int icount_time_shift; + extern int64_t qemu_icount_bias; + int64_t cpu_get_icount(void); Index: patches/patch-sysemu_h =================================================================== RCS file: patches/patch-sysemu_h diff -N patches/patch-sysemu_h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-sysemu_h 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- sysemu.h.orig Fri Jan 21 17:12:57 2011 ++++ sysemu.h Fri Jan 21 17:13:10 2011 +@@ -24,7 +24,7 @@ extern const char *bios_name; + #define QEMU_FILE_TYPE_KEYMAP 1 + char *qemu_find_file(int type, const char *name); + +-extern int vm_running; ++extern volatile sig_atomic_t vm_running; + extern const char *qemu_name; + extern uint8_t qemu_uuid[]; + int qemu_uuid_parse(const char *str, uint8_t *uuid); Index: patches/patch-vl_c =================================================================== RCS file: patches/patch-vl_c diff -N patches/patch-vl_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-vl_c 21 Jan 2011 17:24:09 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- vl.c.orig Fri Jan 21 17:44:37 2011 ++++ vl.c Fri Jan 21 17:44:46 2011 +@@ -180,7 +180,7 @@ int mem_prealloc = 0; /* force preallocation of physic + #endif + int nb_nics; + NICInfo nd_table[MAX_NICS]; +-int vm_running; ++volatile sig_atomic_t vm_running; + int autostart; + int incoming_expected; /* Started with -incoming and waiting for incoming */ + static int rtc_utc = 1;