public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* collect some information when qemu-kvm exit
@ 2011-06-22 12:27 lidong chen
  2011-06-23  9:05 ` lidong chen
  0 siblings, 1 reply; 11+ messages in thread
From: lidong chen @ 2011-06-22 12:27 UTC (permalink / raw)
  To: kvm

I find qemu-kvm only output a little information when abnormally exit.
For example, if qemu-kvm exit by segmentation fault, there are no
information in /var/log/libvirt/qemu/xx.log.

so i want to solve this by collect some information when qemu-kvm exit.

my idea is register some signal handler, and print some debug
information in the signal handler function. and use atexit register a
function for process termination.

the main thread already used SIGBUS,SIGUSR2,SIGALRM,SIGIO. and  vcpu
thread used SIGBUS,SIGIPI.

the signal that should register for vcpu thread.
   SIGHUP,
   SIGINT,
   SIGQUIT,
   SIGILL,
   SIGTRAP,
   SIGABRT,
   SIGFPE,
   SIGUSR1,
   SIGPIPE,
   SIGSEGV,
   SIGUSR2,
   SIGTERM,
   SIGSTKFLT,
   SIGTSTP,
   SIGXCPU,
   SIGXFSZ,
   SIGVTALRM,
   SIGIO,
   SIGSYS,

the signal that should register for main thread.
   SIGHUP,
   SIGINT,
   SIGQUIT,
   SIGILL,
   SIGTRAP,
   SIGABRT,
   SIGFPE,
   SIGUSR1,
   SIGPIPE,
   SIGSEGV,
   SIGTERM,
   SIGSTKFLT,
   SIGTSTP,
   SIGXCPU,
   SIGXFSZ,
   SIGVTALRM,
   SIGSYS,

the simple example for this function:
--- ../../BUILD/qemu-kvm-0.12.5/vl.c 2011-05-25 04:08:00.000000000 -0400
+++ vl.c 2011-06-22 06:57:51.000000000 -0400
+static void sig_handler(int n)
+{
+         int j, nptrs;
+       #define SIZE 100
+           void *buffer[100];
+           char **strings;
+
+           nptrs = backtrace(buffer, SIZE);
+           printf("backtrace() returned %d addresses\n", nptrs);
+
+           /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
+              would produce similar output to the following: */
+
+           strings = backtrace_symbols(buffer, nptrs);
+           if (strings == NULL) {
+               perror("backtrace_symbols");
+               exit(EXIT_FAILURE);
+           }
+
+           for (j = 0; j < nptrs; j++)
+               printf("%s\n", strings[j]);
+
+           free(strings);
+
+       abort();
+}
+
+void bye(void) {
+        printf("That was all, folks\n");
+         int j, nptrs;
+       #define SIZE 100
+           void *buffer[100];
+           char **strings;
+
+           nptrs = backtrace(buffer, SIZE);
+           printf("backtrace() returned %d addresses\n", nptrs);
+
+           /* The call backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO)
+              would produce similar output to the following: */
+
+           strings = backtrace_symbols(buffer, nptrs);
+           if (strings == NULL) {
+               perror("backtrace_symbols");
+               exit(EXIT_FAILURE);
+           }
+
+           for (j = 0; j < nptrs; j++)
+               printf("%s\n", strings[j]);
+
+           free(strings);
+
+}
+
+
int main(int argc, char **argv, char **envp)
{
    const char *gdbstub_dev = NULL;
@@ -4954,6 +5010,17 @@

    init_clocks();

+
+    signal(SIGSEGV, sig_handler);
+
+    i = atexit(bye);
+    if (i != 0) {
+           fprintf(stderr, "cannot set exit function\n");
+           return EXIT_FAILURE;
+    }
+
+
+

--- ../../BUILD/qemu-kvm-0.12.5/qemu-kvm.c    2011-05-25
03:31:25.000000000 -0400
+++ qemu-kvm.c    2011-06-22 07:04:05.000000000 -0400
@@ -1883,6 +1883,10 @@

+
static void *ap_main_loop(void *_env)
{
    CPUState *env = _env;
@@ -1908,10 +1927,10 @@
    struct ioperm_data *data = NULL;
#endif

    current_env = env;
    env->thread_id = kvm_get_thread_id();
    sigfillset(&signals);
+    sigdelset(&signals,SIGSEGV);
    sigprocmask(SIG_BLOCK, &signals, NULL);
    kvm_create_vcpu(env, env->cpu_index);

the log in /var/log/libvirt/qemu/xx.log.

LC_ALL=C PATH=/bin:/sbin:/usr/bin:/usr/sbin HOME=/ QEMU_AUDIO_DRV=none
/usr/bin/qemu-kvm -S -M pc-0.12 -enable-kvm -m 9767 -smp
16,sockets=16,cores=1,threads=1 -name sles11-4 -uuid
52841129-6b46-fef5-6a62-11c422597206 -nodefaults -chardev
socket,id=monitor,path=/var/lib/libvirt/qemu/sles11-4.monitor,server,nowait
-mon chardev=monitor,mode=readline -no-reboot -boot dc -drive
file=/mnt/disk2/c00104598/sles11sp1.raw,if=none,id=drive-virtio-disk0,boot=on
-device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0
-drive file=/opt/c00104598/iso/SLES-11-SP1.iso,if=none,media=cdrom,id=drive-ide0-1-0
-device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
-device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:24:a5:1d,bus=pci.0,addr=0x5
-net tap,fd=15,vlan=0,name=hostnet0 -usb -vnc *:0 -k en-us -vga cirrus
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
19:22:40.436: debug : qemuSecurityDACSetProcessLabel:411 : Dropping
privileges of VM to 0:0
backtrace() returned 16 addresses
/usr/bin/qemu-kvm(bye+0x2b) [0x43346e]
/lib64/libc.so.6(+0x355e5) [0x7f45c50605e5]
/lib64/libc.so.6(+0x35635) [0x7f45c5060635]
/usr/bin/qemu-kvm() [0x4489e2]
/usr/bin/qemu-kvm(virtio_queue_notify+0x89) [0x5bb841]
/usr/bin/qemu-kvm() [0x449bb3]
/usr/bin/qemu-kvm() [0x44a077]
/usr/bin/qemu-kvm() [0x4f2cb4]
/usr/bin/qemu-kvm(cpu_outw+0x20) [0x4f305d]
/usr/bin/qemu-kvm() [0x4513f8]
/usr/bin/qemu-kvm(kvm_run+0x2e0) [0x4539bb]
/usr/bin/qemu-kvm(kvm_cpu_exec+0x15) [0x454c8c]
/usr/bin/qemu-kvm() [0x45541f]
/usr/bin/qemu-kvm() [0x455571]
/lib64/libpthread.so.0(+0x75f0) [0x7f45c75905f0]
/lib64/libc.so.6(clone+0x6d) [0x7f45c50ff84d]

my question :
for vcpu thread, why block all signal except SIGBUS SIGIPI? is it safe
to do register another signal?

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-07-07  1:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-22 12:27 collect some information when qemu-kvm exit lidong chen
2011-06-23  9:05 ` lidong chen
2011-06-23 10:13   ` Jan Kiszka
2011-06-23 13:56     ` lidong chen
2011-06-23 14:51       ` Jan Kiszka
2011-06-24  8:24         ` lidong chen
2011-06-24  8:55           ` Jan Kiszka
2011-06-24  8:58             ` Jan Kiszka
2011-06-24 13:26               ` lidong chen
2011-07-02 11:22                 ` lidong chen
2011-07-07  1:20                   ` lidong chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox