From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZCf9-0001Ya-T0 for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:31:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZCf6-0001Uc-OA for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:31:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55476) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gZCf5-0001Ng-Gb for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:31:40 -0500 Date: Tue, 18 Dec 2018 10:31:33 +0000 From: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= Message-ID: <20181218103133.GB22638@redhat.com> Reply-To: Daniel =?utf-8?B?UC4gQmVycmFuZ8Op?= References: <20181217202602.31113-1-r.bolshakov@yadro.com> <20181217202602.31113-3-r.bolshakov@yadro.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20181217202602.31113-3-r.bolshakov@yadro.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [RFC 2/2] qemu-thread: Don't block SEGV, ILL and FPE List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roman Bolshakov , Paolo Bonzini Cc: qemu-devel@nongnu.org On Mon, Dec 17, 2018 at 11:26:02PM +0300, Roman Bolshakov wrote: > If any of these signals happen on macOS, they are not delivered to othe= r > threads and signalfd_compat receives nothing. Indeed, POSIX reference > and sigprocmask(2) note that an attempt to block the signals results in > undefined behaviour. SEGV and FPE can't also be received by signalfd(2) > on Linux. > > An ability to retrieve SIGBUS via signalfd(2) is used by QEMU for > memory preallocation therefore we can't unblock it without consequences= . > But it's important to leave a remark that the signal is lost on macOS. Specifically Linux manpage says "If SIGBUS, SIGFPE, SIGILL, or SIGSEGV are generated while they are blocked, the result is undefined, unless the signal was=20 generated by kill(2), sigqueue(3), or raise(3)." It appears as if Linux will deliver those signals to a different thread where they're not blocked, but macOS will simply discard the signals. Linux behaviour is more helpful, but both are compliant since behaviour is explicitly undefined. So really we should not have code that relies on being able to block any of BUS, FPE, ILL or SEGV. Allowing FPE, ILL & SEGV looks trivial since nothing in QEMU tries to handle them, so it'll just trigger the OS default signal handler which will abort. As noted code is seeming to rely on catching BUS which is a problem and I'm not clear how, or even if, we can remove that and thus unblock the signals. Copying Paolo, since this unconditional blocking of all signals was added in commit 55541c8afc1a2d75de890c6ee858769d7d605526 Author: Paolo Bonzini Date: Thu Jun 3 15:20:32 2010 +0200 make qemu_thread_create block all signals =20 All signals will thus be routed through the IO thread. =20 Signed-off-by: Paolo Bonzini Signed-off-by: Anthony Liguori >=20 > Signed-off-by: Roman Bolshakov > --- > util/qemu-thread-posix.c | 5 +++++ > 1 file changed, 5 insertions(+) >=20 > diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c > index c6934bd22c..1bf5e65dea 100644 > --- a/util/qemu-thread-posix.c > +++ b/util/qemu-thread-posix.c > @@ -524,6 +524,11 @@ void qemu_thread_create(QemuThread *thread, const = char *name, > =20 > /* Leave signal handling to the iothread. */ > sigfillset(&set); > + /* Blocking the signals can result in undefined behaviour. */ > + sigdelset(&set, SIGSEGV); > + sigdelset(&set, SIGFPE); > + sigdelset(&set, SIGILL); > + /* TODO avoid SIGBUS loss on macOS */ > pthread_sigmask(SIG_SETMASK, &set, &oldset); Regardless of what we do with SIGBUS, this addition looks fine to me on its own so Reviewed-by: Daniel P. Berrang=C3=A9 Regards, Daniel --=20 |: https://berrange.com -o- https://www.flickr.com/photos/dberran= ge :| |: https://libvirt.org -o- https://fstop138.berrange.c= om :| |: https://entangle-photo.org -o- https://www.instagram.com/dberran= ge :|