From nobody Mon Apr 29 00:40:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yadro.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545079534767957.284493650414; Mon, 17 Dec 2018 12:45:34 -0800 (PST) Received: from localhost ([::1]:49458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYzld-0003Nd-ND for importer@patchew.org; Mon, 17 Dec 2018 15:45:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48650) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYzhj-0008Un-Dz for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:41:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYzTd-0005IG-Bn for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:26:58 -0500 Received: from mta-01.yadro.com ([89.207.88.251]:45318) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gYzTc-0005Gv-VV for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:26:57 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id C6AFC4193F for ; Mon, 17 Dec 2018 20:26:55 +0000 (UTC) Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zBXVN1kUryVs for ; Mon, 17 Dec 2018 23:26:54 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id BE4654193A for ; Mon, 17 Dec 2018 23:26:54 +0300 (MSK) Received: from localhost (172.17.1.6) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Mon, 17 Dec 2018 23:26:54 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1545078414; x=1546892815; bh=159Xf3Ff2LooeDS+/jKAJxb5TB5AIKNR3+z /ZkTQKiI=; b=OPkM+r4/e1T/rcBRK1j4gKkxOXq2SNDR2inzFJUC+xkLzkGAZWN 0DlXf6Nf7Vz/ys7w74A+46ejhBuYTiGDJCjSgzZ6Gkp1GjuLnNLQVucb6vhtV9JU IvfMWRnljfdfOjh7zofq4DpOrcTsLA/PZzNX9YkTRjYTOkhNDMRdubgE= X-Virus-Scanned: amavisd-new at yadro.com From: Roman Bolshakov To: Date: Mon, 17 Dec 2018 23:26:01 +0300 Message-ID: <20181217202602.31113-2-r.bolshakov@yadro.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181217202602.31113-1-r.bolshakov@yadro.com> References: <20181217202602.31113-1-r.bolshakov@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.1.6] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 89.207.88.251 Subject: [Qemu-devel] [RFC 1/2] util: Implement debug-threads for macOS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Bolshakov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" macOS provides pthread_setname_np that doesn't have thread id argument. Signed-off-by: Roman Bolshakov Reviewed-by: Daniel P. Berrang=C3=A9 --- configure | 32 ++++++++++++++++++++++++++------ qemu-options.hx | 4 ++-- util/qemu-thread-posix.c | 6 +++++- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 224d3071ac..99dc073e53 100755 --- a/configure +++ b/configure @@ -3715,8 +3715,8 @@ if test "$mingw32" !=3D yes -a "$pthread" =3D no; then "Make sure to have the pthread libs and headers installed." fi =20 -# check for pthread_setname_np -pthread_setname_np=3Dno +# check for pthread_setname_np with thread id +pthread_setname_np_w_tid=3Dno cat > $TMPC << EOF #include =20 @@ -3730,7 +3730,24 @@ int main(void) } EOF if compile_prog "" "$pthread_lib" ; then - pthread_setname_np=3Dyes + pthread_setname_np_w_tid=3Dyes +fi + +# check for pthread_setname_np without thread id +pthread_setname_np_wo_tid=3Dno +cat > $TMPC << EOF +#include + +static void *f(void *p) { pthread_setname_np("QEMU"); } +int main(void) +{ + pthread_t thread; + pthread_create(&thread, 0, f, 0); + return 0; +} +EOF +if compile_prog "" "$pthread_lib" ; then + pthread_setname_np_wo_tid=3Dyes fi =20 ########################################## @@ -6883,11 +6900,14 @@ fi # Hold two types of flag: # CONFIG_THREAD_SETNAME_BYTHREAD - we've got a way of setting the name = on # a thread we have a handle to -# CONFIG_PTHREAD_SETNAME_NP - A way of doing it on a particular +# CONFIG_PTHREAD_SETNAME_NP_W_TID - A way of doing it on a particular # platform -if test "$pthread_setname_np" =3D "yes" ; then +if test "$pthread_setname_np_w_tid" =3D "yes" ; then echo "CONFIG_THREAD_SETNAME_BYTHREAD=3Dy" >> $config_host_mak - echo "CONFIG_PTHREAD_SETNAME_NP=3Dy" >> $config_host_mak + echo "CONFIG_PTHREAD_SETNAME_NP_W_TID=3Dy" >> $config_host_mak +elif test "$pthread_setname_np_wo_tid" =3D "yes" ; then + echo "CONFIG_THREAD_SETNAME_BYTHREAD=3Dy" >> $config_host_mak + echo "CONFIG_PTHREAD_SETNAME_NP_WO_TID=3Dy" >> $config_host_mak fi =20 if test "$vxhs" =3D "yes" ; then diff --git a/qemu-options.hx b/qemu-options.hx index df42116ecc..d4f3564b78 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -538,8 +538,8 @@ ETEXI DEF("name", HAS_ARG, QEMU_OPTION_name, "-name string1[,process=3Dstring2][,debug-threads=3Don|off]\n" " set the name of the guest\n" - " string1 sets the window title and string2 the process= name (on Linux)\n" - " When debug-threads is enabled, individual threads are= given a separate name (on Linux)\n" + " string1 sets the window title and string2 the process= name\n" + " When debug-threads is enabled, individual threads are= given a separate name\n" " NOTE: The thread names are for debugging and not a st= able API.\n", QEMU_ARCH_ALL) STEXI diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 865e476df5..c6934bd22c 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -484,12 +484,16 @@ static void *qemu_thread_start(void *args) void *arg =3D qemu_thread_args->arg; void *r; =20 -#ifdef CONFIG_PTHREAD_SETNAME_NP +#ifdef CONFIG_THREAD_SETNAME_BYTHREAD /* Attempt to set the threads name; note that this is for debug, so * we're not going to fail if we can't set it. */ if (name_threads && qemu_thread_args->name) { +# if defined(CONFIG_PTHREAD_SETNAME_NP_W_TID) pthread_setname_np(pthread_self(), qemu_thread_args->name); +# elif defined(CONFIG_PTHREAD_SETNAME_NP_WO_TID) + pthread_setname_np(qemu_thread_args->name); +# endif } #endif g_free(qemu_thread_args->name); --=20 2.19.1 From nobody Mon Apr 29 00:40:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yadro.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1545079483003604.4599292868887; Mon, 17 Dec 2018 12:44:43 -0800 (PST) Received: from localhost ([::1]:49452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYzkn-0002oI-UI for importer@patchew.org; Mon, 17 Dec 2018 15:44:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYzhi-000066-MX for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:41:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYzTj-0005Oo-VS for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:27:04 -0500 Received: from mta-01.yadro.com ([89.207.88.251]:45328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gYzTj-0005Nh-NY for qemu-devel@nongnu.org; Mon, 17 Dec 2018 15:27:03 -0500 Received: from localhost (unknown [127.0.0.1]) by mta-01.yadro.com (Postfix) with ESMTP id 860134193F for ; Mon, 17 Dec 2018 20:27:02 +0000 (UTC) Received: from mta-01.yadro.com ([127.0.0.1]) by localhost (mta-01.yadro.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a3n8KS8GPGQO for ; Mon, 17 Dec 2018 23:27:01 +0300 (MSK) Received: from T-EXCH-02.corp.yadro.com (t-exch-02.corp.yadro.com [172.17.10.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mta-01.yadro.com (Postfix) with ESMTPS id AEC8C4193A for ; Mon, 17 Dec 2018 23:27:01 +0300 (MSK) Received: from localhost (172.17.1.6) by T-EXCH-02.corp.yadro.com (172.17.10.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.32; Mon, 17 Dec 2018 23:27:01 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=yadro.com; h= content-type:content-type:content-transfer-encoding:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received:received; s=mta-01; t= 1545078421; x=1546892822; bh=6AWDkfgSow1jy/x/NVlX5+KLFCuI+251+U6 GSGwadc4=; b=tufMtSlDM382y59wVu+/Mq2CWS/w+SJ1eB+t5ffpfg1A4fJkIPm eCXpRQagzRe2VY5omV4mvj8JNm8BAEzV4pp5Vp73cXZ3TbgMBJGatHnTANxPwQDe GwuiRh7wi2f4GGmjcvUhnM7YNbkZg6MZjwa+iiux9WTom0CyonaOfASg= X-Virus-Scanned: amavisd-new at yadro.com From: Roman Bolshakov To: Date: Mon, 17 Dec 2018 23:26:02 +0300 Message-ID: <20181217202602.31113-3-r.bolshakov@yadro.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181217202602.31113-1-r.bolshakov@yadro.com> References: <20181217202602.31113-1-r.bolshakov@yadro.com> MIME-Version: 1.0 X-Originating-IP: [172.17.1.6] X-ClientProxiedBy: T-EXCH-01.corp.yadro.com (172.17.10.101) To T-EXCH-02.corp.yadro.com (172.17.10.102) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 89.207.88.251 Subject: [Qemu-devel] [RFC 2/2] qemu-thread: Don't block SEGV, ILL and FPE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Roman Bolshakov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If any of these signals happen on macOS, they are not delivered to other 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. Signed-off-by: Roman Bolshakov Reviewed-by: Daniel P. Berrang=C3=A9 --- util/qemu-thread-posix.c | 5 +++++ 1 file changed, 5 insertions(+) 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); =20 qemu_thread_args =3D g_new0(QemuThreadArgs, 1); --=20 2.19.1