qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: kvm@vger.kernel.org
Subject: [Qemu-devel] Re: [PATCH 13/22] Set up signalfd under !CONFIG_IOTHREAD
Date: Fri, 28 Jan 2011 09:11:32 +0100	[thread overview]
Message-ID: <ihttnj$if8$3@dough.gmane.org> (raw)
In-Reply-To: <451506b201a2c9a84db6af26d23be751d2e65f74.1296133797.git.jan.kiszka@siemens.com>

On 01/27/2011 02:09 PM, Jan Kiszka wrote:
> Will be required for SIGBUS handling. For obvious reasons, this will
> remain a nop on Windows hosts.
>
> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
> ---
>   Makefile.objs |    2 +-
>   cpus.c        |  117 +++++++++++++++++++++++++++++++--------------------------
>   2 files changed, 65 insertions(+), 54 deletions(-)
>
> diff --git a/Makefile.objs b/Makefile.objs
> index c3e52c5..81b9a5b 100644
> --- a/Makefile.objs
> +++ b/Makefile.objs
> @@ -141,7 +141,7 @@ common-obj-y += $(addprefix ui/, $(ui-obj-y))
>
>   common-obj-y += iov.o acl.o
>   common-obj-$(CONFIG_THREAD) += qemu-thread.o
> -common-obj-$(CONFIG_IOTHREAD) += compatfd.o
> +common-obj-$(CONFIG_POSIX) += compatfd.o
>   common-obj-y += notify.o event_notifier.o
>   common-obj-y += qemu-timer.o qemu-timer-common.o
>
> diff --git a/cpus.c b/cpus.c
> index 558c0d3..fc3f222 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -261,6 +261,59 @@ static void qemu_kvm_init_cpu_signals(CPUState *env)
>       }
>   }
>
> +/* If we have signalfd, we mask out the signals we want to handle and then
> + * use signalfd to listen for them.  We rely on whatever the current signal
> + * handler is to dispatch the signals when we receive them.
> + */
> +static void sigfd_handler(void *opaque)
> +{
> +    int fd = (unsigned long) opaque;
> +    struct qemu_signalfd_siginfo info;
> +    struct sigaction action;
> +    ssize_t len;
> +
> +    while (1) {
> +        do {
> +            len = read(fd,&info, sizeof(info));
> +        } while (len == -1&&  errno == EINTR);
> +
> +        if (len == -1&&  errno == EAGAIN) {
> +            break;
> +        }
> +
> +        if (len != sizeof(info)) {
> +            printf("read from sigfd returned %zd: %m\n", len);
> +            return;
> +        }
> +
> +        sigaction(info.ssi_signo, NULL,&action);
> +        if ((action.sa_flags&  SA_SIGINFO)&&  action.sa_sigaction) {
> +            action.sa_sigaction(info.ssi_signo,
> +                                (siginfo_t *)&info, NULL);
> +        } else if (action.sa_handler) {
> +            action.sa_handler(info.ssi_signo);
> +        }
> +    }
> +}
> +
> +static int qemu_signalfd_init(sigset_t mask)
> +{
> +    int sigfd;
> +
> +    sigfd = qemu_signalfd(&mask);
> +    if (sigfd == -1) {
> +        fprintf(stderr, "failed to create signalfd\n");
> +        return -errno;
> +    }
> +
> +    fcntl_setfl(sigfd, O_NONBLOCK);
> +
> +    qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
> +                         (void *)(unsigned long) sigfd);
> +
> +    return 0;
> +}
> +
>   static void qemu_kvm_eat_signals(CPUState *env)
>   {
>       struct timespec ts = { 0, 0 };
> @@ -340,6 +393,17 @@ static void qemu_kvm_eat_signals(CPUState *env)
>   #ifndef CONFIG_IOTHREAD
>   int qemu_init_main_loop(void)
>   {
> +#ifndef _WIN32
> +    sigset_t blocked_signals;
> +    int ret;
> +
> +    sigemptyset(&blocked_signals);
> +
> +    ret = qemu_signalfd_init(blocked_signals);
> +    if (ret) {
> +        return ret;
> +    }
> +#endif
>       cpu_set_debug_excp_handler(cpu_debug_handler);
>
>       return qemu_event_init();
> @@ -431,41 +495,6 @@ static QemuCond qemu_system_cond;
>   static QemuCond qemu_pause_cond;
>   static QemuCond qemu_work_cond;
>
> -/* If we have signalfd, we mask out the signals we want to handle and then
> - * use signalfd to listen for them.  We rely on whatever the current signal
> - * handler is to dispatch the signals when we receive them.
> - */
> -static void sigfd_handler(void *opaque)
> -{
> -    int fd = (unsigned long) opaque;
> -    struct qemu_signalfd_siginfo info;
> -    struct sigaction action;
> -    ssize_t len;
> -
> -    while (1) {
> -        do {
> -            len = read(fd,&info, sizeof(info));
> -        } while (len == -1&&  errno == EINTR);
> -
> -        if (len == -1&&  errno == EAGAIN) {
> -            break;
> -        }
> -
> -        if (len != sizeof(info)) {
> -            printf("read from sigfd returned %zd: %m\n", len);
> -            return;
> -        }
> -
> -        sigaction(info.ssi_signo, NULL,&action);
> -        if ((action.sa_flags&  SA_SIGINFO)&&  action.sa_sigaction) {
> -            action.sa_sigaction(info.ssi_signo,
> -                                (siginfo_t *)&info, NULL);
> -        } else if (action.sa_handler) {
> -            action.sa_handler(info.ssi_signo);
> -        }
> -    }
> -}
> -
>   static void cpu_signal(int sig)
>   {
>       if (cpu_single_env) {
> @@ -517,24 +546,6 @@ static sigset_t block_io_signals(void)
>       return set;
>   }
>
> -static int qemu_signalfd_init(sigset_t mask)
> -{
> -    int sigfd;
> -
> -    sigfd = qemu_signalfd(&mask);
> -    if (sigfd == -1) {
> -        fprintf(stderr, "failed to create signalfd\n");
> -        return -errno;
> -    }
> -
> -    fcntl_setfl(sigfd, O_NONBLOCK);
> -
> -    qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL,
> -                         (void *)(unsigned long) sigfd);
> -
> -    return 0;
> -}
> -
>   int qemu_init_main_loop(void)
>   {
>       int ret;

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

  reply	other threads:[~2011-01-28  8:25 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 13:09 [Qemu-devel] [PATCH 00/22] [uq/master] Patch queue, part II Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 01/22] Prevent abortion on multiple VCPU kicks Jan Kiszka
2011-01-31  9:44   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:19     ` Jan Kiszka
2011-01-31 13:16       ` Avi Kivity
2011-01-27 13:09 ` [Qemu-devel] [PATCH 02/22] Stop current VCPU on synchronous reset requests Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 03/22] Process vmstop requests in IO thread Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 04/22] Leave inner main_loop faster on pending requests Jan Kiszka
2011-01-31  9:52   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:22     ` Jan Kiszka
2011-01-31 13:17       ` Avi Kivity
2011-01-31 14:32         ` Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 05/22] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 06/22] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 07/22] kvm: Handle kvm_init_vcpu errors Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 08/22] kvm: Provide sigbus services arch-independently Jan Kiszka
2011-01-27 16:39   ` [Qemu-devel] " Paolo Bonzini
2011-01-30 14:51   ` Alexander Graf
2011-01-27 13:09 ` [Qemu-devel] [PATCH 09/22] Refactor signal setup functions in cpus.c Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 10/22] kvm: Set up signal mask also for !CONFIG_IOTHREAD Jan Kiszka
2011-01-28  8:08   ` [Qemu-devel] " Paolo Bonzini
2011-01-27 13:09 ` [Qemu-devel] [PATCH 11/22] kvm: Refactor qemu_kvm_eat_signals Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 12/22] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Jan Kiszka
2011-01-28  8:09   ` [Qemu-devel] " Paolo Bonzini
2011-02-01 12:38   ` Marcelo Tosatti
2011-02-01 12:49     ` Marcelo Tosatti
2011-02-01 13:21     ` Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 13/22] Set up signalfd " Jan Kiszka
2011-01-28  8:11   ` Paolo Bonzini [this message]
2011-01-27 13:09 ` [Qemu-devel] [PATCH 14/22] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Jan Kiszka
2011-01-27 14:20   ` [Qemu-devel] [PATCH v2 " Jan Kiszka
2011-01-27 14:33     ` [Qemu-devel] [PATCH v3 " Jan Kiszka
2011-01-31 10:03       ` [Qemu-devel] " Avi Kivity
2011-01-31 11:27         ` Jan Kiszka
2011-01-31 12:13           ` Stefan Hajnoczi
2011-01-31 12:18             ` Jan Kiszka
2011-01-31 13:35               ` Stefan Hajnoczi
2011-01-31 13:22           ` Avi Kivity
2011-01-31 14:31             ` Jan Kiszka
2011-01-31 16:30               ` Avi Kivity
2011-02-01 12:47   ` [Qemu-devel] Re: [PATCH " Marcelo Tosatti
2011-02-01 13:32     ` Jan Kiszka
2011-02-01 13:48       ` Marcelo Tosatti
2011-02-01 13:58         ` Jan Kiszka
2011-02-01 14:10           ` Marcelo Tosatti
2011-02-01 14:21             ` Jan Kiszka
2011-02-01 14:37               ` Jan Kiszka
2011-02-01 14:45                 ` Jan Kiszka
2011-01-27 13:09 ` [Qemu-devel] [PATCH 15/22] kvm: Add MCE signal support for !CONFIG_IOTHREAD Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 16/22] Introduce VCPU self-signaling service Jan Kiszka
2011-02-01 13:14   ` [Qemu-devel] " Marcelo Tosatti
2011-02-01 13:33     ` Jan Kiszka
2011-02-01 13:50       ` Marcelo Tosatti
2011-02-01 13:59         ` Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 17/22] kvm: Move irqchip event processing out of inner loop Jan Kiszka
2011-01-31 10:08   ` [Qemu-devel] " Avi Kivity
2011-01-31 11:36     ` Jan Kiszka
2011-01-31 13:04       ` Jan Kiszka
2011-01-31 15:40         ` Jan Kiszka
2011-01-31 16:38           ` Gleb Natapov
2011-01-31 16:41             ` Jan Kiszka
2011-01-31 16:45               ` Jan Kiszka
2011-01-31 16:50               ` Gleb Natapov
2011-01-31 16:52                 ` Jan Kiszka
2011-01-31 16:56                   ` Gleb Natapov
2011-01-31 18:06                     ` [Qemu-devel] [PATCH v2 17&18/22] kvm: Unconditionally reenter kernel after IO exits Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 18/22] " Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 19/22] kvm: Remove static return code of kvm_handle_io Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 20/22] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 21/22] Refactor kvm&tcg function names in cpus.c Jan Kiszka
2011-01-27 13:10 ` [Qemu-devel] [PATCH 22/22] Fix a few coding style violations " Jan Kiszka
2011-01-31 10:12 ` [Qemu-devel] Re: [PATCH 00/22] [uq/master] Patch queue, part II Avi Kivity
2011-01-31 12:03   ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='ihttnj$if8$3@dough.gmane.org' \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).