Re: collect some information when qemu-kvm exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I didn't understand why need block all signal except SIGBUS SIGIPI for
vcpu thread? is it safe to register another signal handler?
if somebody know the reason, please tell me.

and is it worth to do this?

2011/6/22 lidong chen <chen.lidong.kernel@xxxxxxxxx>:
> 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?
>
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux