From nobody Wed Nov 5 16:45:31 2025 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536059523599895.6124814583267; Tue, 4 Sep 2018 04:12:03 -0700 (PDT) Received: from localhost ([::1]:50251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9FU-0003hQ-CT for importer@patchew.org; Tue, 04 Sep 2018 07:11:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9DG-0001H2-26 for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fx9DD-0006Lh-OC for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:38 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:40788) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fx9DD-0006L0-DJ for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:35 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 04 Sep 2018 13:09:32 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 19:08:18 +0800 Message-Id: <20180904110822.12863-2-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904110822.12863-1-fli@suse.com> References: <20180904110822.12863-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH 1/5] Fix segmentation fault when qemu_signal_init fails 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: fli@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently, when qemu_signal_init() fails it only returns a non-zero value but without propagating any Error. But its callers need a non-null err when runs error_report_err(err), or else 0->msg occurs. To avoid such segmentation fault, add a new Error parameter to make the call trace to propagate the err to the final caller. Signed-off-by: Fei Li --- include/qemu/osdep.h | 2 +- util/compatfd.c | 17 ++++++++++++----- util/main-loop.c | 11 +++++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index a91068df0e..09ed85fcb8 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -421,7 +421,7 @@ struct qemu_signalfd_siginfo { additional fields in the future) */ }; =20 -int qemu_signalfd(const sigset_t *mask); +int qemu_signalfd(const sigset_t *mask, Error **errp); void sigaction_invoke(struct sigaction *action, struct qemu_signalfd_siginfo *info); #endif diff --git a/util/compatfd.c b/util/compatfd.c index 980bd33e52..65501de622 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "qemu-common.h" #include "qemu/thread.h" +#include "qapi/error.h" =20 #include =20 @@ -65,7 +66,7 @@ static void *sigwait_compat(void *opaque) } } =20 -static int qemu_signalfd_compat(const sigset_t *mask) +static int qemu_signalfd_compat(const sigset_t *mask, Error **errp) { struct sigfd_compat_info *info; QemuThread thread; @@ -73,11 +74,13 @@ static int qemu_signalfd_compat(const sigset_t *mask) =20 info =3D malloc(sizeof(*info)); if (info =3D=3D NULL) { + error_setg(errp, "Failed to malloc in %s", __func__); errno =3D ENOMEM; return -1; } =20 if (pipe(fds) =3D=3D -1) { + error_setg(errp, "Failed to create a pipe in %s", __func__); free(info); return -1; } @@ -94,17 +97,21 @@ static int qemu_signalfd_compat(const sigset_t *mask) return fds[0]; } =20 -int qemu_signalfd(const sigset_t *mask) +int qemu_signalfd(const sigset_t *mask, Error **errp) { -#if defined(CONFIG_SIGNALFD) int ret; + Error *local_err =3D NULL; =20 +#if defined(CONFIG_SIGNALFD) ret =3D syscall(SYS_signalfd, -1, mask, _NSIG / 8); if (ret !=3D -1) { qemu_set_cloexec(ret); return ret; } #endif - - return qemu_signalfd_compat(mask); + ret =3D qemu_signalfd_compat(mask, &local_err); + if (local_err) { + error_propagate(errp, local_err); + } + return ret; } diff --git a/util/main-loop.c b/util/main-loop.c index affe0403c5..20f6ad3849 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -71,10 +71,11 @@ static void sigfd_handler(void *opaque) } } =20 -static int qemu_signal_init(void) +static int qemu_signal_init(Error **errp) { int sigfd; sigset_t set; + Error *local_err =3D NULL; =20 /* * SIG_IPI must be blocked in the main thread and must not be caught @@ -94,9 +95,10 @@ static int qemu_signal_init(void) pthread_sigmask(SIG_BLOCK, &set, NULL); =20 sigdelset(&set, SIG_IPI); - sigfd =3D qemu_signalfd(&set); + sigfd =3D qemu_signalfd(&set, &local_err); if (sigfd =3D=3D -1) { fprintf(stderr, "failed to create signalfd\n"); + error_propagate(errp, local_err); return -errno; } =20 @@ -109,7 +111,7 @@ static int qemu_signal_init(void) =20 #else /* _WIN32 */ =20 -static int qemu_signal_init(void) +static int qemu_signal_init(Error **errp) { return 0; } @@ -148,8 +150,9 @@ int qemu_init_main_loop(Error **errp) =20 init_clocks(qemu_timer_notify_cb); =20 - ret =3D qemu_signal_init(); + ret =3D qemu_signal_init(&local_error); if (ret) { + error_propagate(errp, local_error); return ret; } =20 --=20 2.13.7 From nobody Wed Nov 5 16:45:31 2025 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536059649567674.0640275133044; Tue, 4 Sep 2018 04:14:09 -0700 (PDT) Received: from localhost ([::1]:50261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9Hc-0006VD-HD for importer@patchew.org; Tue, 04 Sep 2018 07:14:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50285) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9DH-0001L2-4j for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fx9DG-0006Nv-3d for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:39 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:52209) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fx9DF-0006Mo-Nl for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:37 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 04 Sep 2018 13:09:34 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 19:08:19 +0800 Message-Id: <20180904110822.12863-3-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904110822.12863-1-fli@suse.com> References: <20180904110822.12863-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH 2/5] ui/vnc.c: polish vnc_init_func 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: fli@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a new Error parameter to vnc_display_init() and handle the Error in its caller: vnc_init_func() just like vnc_display_open() does. And let the call trace propagate the Error. Signed-off-by: Fei Li --- include/ui/console.h | 2 +- ui/vnc-jobs.c | 2 +- ui/vnc-jobs.h | 2 +- ui/vnc.c | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index fb969caf70..c17803c530 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -453,7 +453,7 @@ void qemu_display_early_init(DisplayOptions *opts); void qemu_display_init(DisplayState *ds, DisplayOptions *opts); =20 /* vnc.c */ -void vnc_display_init(const char *id); +void vnc_display_init(const char *id, Error **errp); void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); int vnc_display_password(const char *id, const char *password); diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index 929391f85d..7c05a1e6df 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -331,7 +331,7 @@ static bool vnc_worker_thread_running(void) return queue; /* Check global queue */ } =20 -void vnc_start_worker_thread(void) +void vnc_start_worker_thread(Error **errp) { VncJobQueue *q; =20 diff --git a/ui/vnc-jobs.h b/ui/vnc-jobs.h index 59f66bcc35..31eb482582 100644 --- a/ui/vnc-jobs.h +++ b/ui/vnc-jobs.h @@ -37,7 +37,7 @@ void vnc_job_push(VncJob *job); void vnc_jobs_join(VncState *vs); =20 void vnc_jobs_consume_buffer(VncState *vs); -void vnc_start_worker_thread(void); +void vnc_start_worker_thread(Error **errp); =20 /* Locks */ static inline int vnc_trylock_display(VncDisplay *vd) diff --git a/ui/vnc.c b/ui/vnc.c index ccb1335d86..ff22bbc055 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3206,9 +3206,10 @@ static const DisplayChangeListenerOps dcl_ops =3D { .dpy_cursor_define =3D vnc_dpy_cursor_define, }; =20 -void vnc_display_init(const char *id) +void vnc_display_init(const char *id, Error **errp) { VncDisplay *vd; + Error *local_err =3D NULL; =20 if (vnc_display_find(id) !=3D NULL) { return; @@ -3236,7 +3237,11 @@ void vnc_display_init(const char *id) vd->connections_limit =3D 32; =20 qemu_mutex_init(&vd->mutex); - vnc_start_worker_thread(); + vnc_start_worker_thread(&local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 vd->dcl.ops =3D &dcl_ops; register_displaychangelistener(&vd->dcl); @@ -4079,7 +4084,11 @@ int vnc_init_func(void *opaque, QemuOpts *opts, Erro= r **errp) char *id =3D (char *)qemu_opts_id(opts); =20 assert(id); - vnc_display_init(id); + vnc_display_init(id, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed to init VNC server: "); + exit(1); + } vnc_display_open(id, &local_err); if (local_err !=3D NULL) { error_reportf_err(local_err, "Failed to start VNC server: "); --=20 2.13.7 From nobody Wed Nov 5 16:45:31 2025 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536059525398671.7018737355402; Tue, 4 Sep 2018 04:12:05 -0700 (PDT) Received: from localhost ([::1]:50252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9Fa-0003jL-94 for importer@patchew.org; Tue, 04 Sep 2018 07:12:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9DJ-0001PW-T3 for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fx9DI-0006Qo-9B for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:41 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:58927) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fx9DH-0006P7-S1 for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:40 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 04 Sep 2018 13:09:36 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 19:08:20 +0800 Message-Id: <20180904110822.12863-4-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904110822.12863-1-fli@suse.com> References: <20180904110822.12863-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH 3/5] qemu_init_vcpu: add a new Error paramater to propagate 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: fli@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The caller of qemu_init_vcpu() already passed the **errp to handle errors. In view of this, add a new Error parameter to the following call trace to propagate the error and let the final caller check it. Signed-off-by: Fei Li --- cpus.c | 32 +++++++++++++++++++------------- include/qom/cpu.h | 2 +- target/alpha/cpu.c | 6 +++++- target/arm/cpu.c | 6 +++++- target/cris/cpu.c | 6 +++++- target/hppa/cpu.c | 6 +++++- target/i386/cpu.c | 6 +++++- target/lm32/cpu.c | 6 +++++- target/m68k/cpu.c | 6 +++++- target/microblaze/cpu.c | 6 +++++- target/mips/cpu.c | 6 +++++- target/moxie/cpu.c | 6 +++++- target/nios2/cpu.c | 6 +++++- target/openrisc/cpu.c | 6 +++++- target/ppc/translate_init.inc.c | 6 +++++- target/riscv/cpu.c | 6 +++++- target/s390x/cpu.c | 5 ++++- target/sh4/cpu.c | 6 +++++- target/sparc/cpu.c | 6 +++++- target/tilegx/cpu.c | 6 +++++- target/tricore/cpu.c | 6 +++++- target/unicore32/cpu.c | 6 +++++- target/xtensa/cpu.c | 6 +++++- 23 files changed, 124 insertions(+), 35 deletions(-) diff --git a/cpus.c b/cpus.c index 8ee6e5db93..41efddc218 100644 --- a/cpus.c +++ b/cpus.c @@ -1898,7 +1898,7 @@ void cpu_remove_sync(CPUState *cpu) /* For temporary buffers for forming a name */ #define VCPU_THREAD_NAME_SIZE 16 =20 -static void qemu_tcg_init_vcpu(CPUState *cpu) +static void qemu_tcg_init_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; static QemuCond *single_tcg_halt_cond; @@ -1954,7 +1954,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) } } =20 -static void qemu_hax_start_vcpu(CPUState *cpu) +static void qemu_hax_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 @@ -1971,7 +1971,7 @@ static void qemu_hax_start_vcpu(CPUState *cpu) #endif } =20 -static void qemu_kvm_start_vcpu(CPUState *cpu) +static void qemu_kvm_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 @@ -1984,7 +1984,7 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } =20 -static void qemu_hvf_start_vcpu(CPUState *cpu) +static void qemu_hvf_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 @@ -2002,7 +2002,7 @@ static void qemu_hvf_start_vcpu(CPUState *cpu) cpu, QEMU_THREAD_JOINABLE); } =20 -static void qemu_whpx_start_vcpu(CPUState *cpu) +static void qemu_whpx_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 @@ -2018,7 +2018,7 @@ static void qemu_whpx_start_vcpu(CPUState *cpu) #endif } =20 -static void qemu_dummy_start_vcpu(CPUState *cpu) +static void qemu_dummy_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; =20 @@ -2031,11 +2031,12 @@ static void qemu_dummy_start_vcpu(CPUState *cpu) QEMU_THREAD_JOINABLE); } =20 -void qemu_init_vcpu(CPUState *cpu) +void qemu_init_vcpu(CPUState *cpu, Error **errp) { cpu->nr_cores =3D smp_cores; cpu->nr_threads =3D smp_threads; cpu->stopped =3D true; + Error *local_err =3D NULL; =20 if (!cpu->as) { /* If the target cpu hasn't set up any address spaces itself, @@ -2046,17 +2047,22 @@ void qemu_init_vcpu(CPUState *cpu) } =20 if (kvm_enabled()) { - qemu_kvm_start_vcpu(cpu); + qemu_kvm_start_vcpu(cpu, &local_err); } else if (hax_enabled()) { - qemu_hax_start_vcpu(cpu); + qemu_hax_start_vcpu(cpu, &local_err); } else if (hvf_enabled()) { - qemu_hvf_start_vcpu(cpu); + qemu_hvf_start_vcpu(cpu, &local_err); } else if (tcg_enabled()) { - qemu_tcg_init_vcpu(cpu); + qemu_tcg_init_vcpu(cpu, &local_err); } else if (whpx_enabled()) { - qemu_whpx_start_vcpu(cpu); + qemu_whpx_start_vcpu(cpu, &local_err); } else { - qemu_dummy_start_vcpu(cpu); + qemu_dummy_start_vcpu(cpu, &local_err); + } + + if (local_err) { + error_propagate(errp, local_err); + return; } =20 while (!cpu->created) { diff --git a/include/qom/cpu.h b/include/qom/cpu.h index dc130cd307..0766e694df 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -1012,7 +1012,7 @@ void end_exclusive(void); * * Initializes a vCPU. */ -void qemu_init_vcpu(CPUState *cpu); +void qemu_init_vcpu(CPUState *cpu, Error **errp); =20 #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */ #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */ diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c index b08078e7fc..5b0b4892f2 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -66,7 +66,11 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error = **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 acc->parent_realize(dev, errp); } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 258ba6dcaa..a06a5629cd 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1028,7 +1028,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Erro= r **errp) } #endif =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } cpu_reset(cs); =20 acc->parent_realize(dev, errp); diff --git a/target/cris/cpu.c b/target/cris/cpu.c index a23aba2688..707ef63293 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -140,7 +140,11 @@ static void cris_cpu_realizefn(DeviceState *dev, Error= **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 ccc->parent_realize(dev, errp); } diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index 00bf444620..45249a505a 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -98,7 +98,11 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } acc->parent_realize(dev, errp); =20 #ifndef CONFIG_USER_ONLY diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f24295e6e4..768039c65b 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5112,7 +5112,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Erro= r **errp) } #endif =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 /* * Most Intel and certain AMD CPUs support hyperthreading. Even though= QEMU diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c index b7499cb627..7c4e4c4d88 100644 --- a/target/lm32/cpu.c +++ b/target/lm32/cpu.c @@ -139,7 +139,11 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error= **errp) =20 cpu_reset(cs); =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 lcc->parent_realize(dev, errp); } diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 582e3a73b3..ed5c340242 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -231,7 +231,11 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error= **errp) m68k_cpu_init_gdb(cpu); =20 cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 mcc->parent_realize(dev, errp); } diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 9b546a2c18..2d82a5885a 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -161,7 +161,11 @@ static void mb_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 env->pvr.regs[0] =3D PVR0_USE_EXC_MASK \ | PVR0_USE_ICACHE_MASK \ diff --git a/target/mips/cpu.c b/target/mips/cpu.c index 497706b669..3e21067f7a 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -136,7 +136,11 @@ static void mips_cpu_realizefn(DeviceState *dev, Error= **errp) cpu_mips_realize_env(&cpu->env); =20 cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 mcc->parent_realize(dev, errp); } diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c index 8d67eb6727..c9e91d7e53 100644 --- a/target/moxie/cpu.c +++ b/target/moxie/cpu.c @@ -66,7 +66,11 @@ static void moxie_cpu_realizefn(DeviceState *dev, Error = **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } cpu_reset(cs); =20 mcc->parent_realize(dev, errp); diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index fbfaa2ce26..be6601fc92 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -94,7 +94,11 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error = **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } cpu_reset(cs); =20 ncc->parent_realize(dev, errp); diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index fb7cb5c507..ee4c931280 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -83,7 +83,11 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Err= or **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } cpu_reset(cs); =20 occ->parent_realize(dev, errp); diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.in= c.c index d920d3e538..50980dec9a 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -9707,7 +9707,11 @@ static void ppc_cpu_realize(DeviceState *dev, Error = **errp) 32, "power-vsx.xml", 0); } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 pcc->parent_realize(dev, errp); =20 diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index d630e8fd6c..5416cf86c2 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -303,7 +303,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error = **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } cpu_reset(cs); =20 mcc->parent_realize(dev, errp); diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 8ed4823d6e..bd362e3775 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -217,7 +217,10 @@ static void s390_cpu_realizefn(DeviceState *dev, Error= **errp) qemu_register_reset(s390_cpu_machine_reset_cb, cpu); #endif s390_cpu_gdb_init(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + goto out; + } =20 /* * KVM requires the initial CPU reset ioctl to be executed on the targ= et diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c index b9f393b7c7..2ad3a8f09e 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -196,7 +196,11 @@ static void superh_cpu_realizefn(DeviceState *dev, Err= or **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 scc->parent_realize(dev, errp); } diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 0f090ece54..b3616f8d59 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -773,7 +773,11 @@ static void sparc_cpu_realizefn(DeviceState *dev, Erro= r **errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 scc->parent_realize(dev, errp); } diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c index bfe9be59b5..59c0850a7c 100644 --- a/target/tilegx/cpu.c +++ b/target/tilegx/cpu.c @@ -92,7 +92,11 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error= **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 tcc->parent_realize(dev, errp); } diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 2edaef1aef..c95d8e9856 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -96,7 +96,11 @@ static void tricore_cpu_realizefn(DeviceState *dev, Erro= r **errp) set_feature(env, TRICORE_FEATURE_13); } cpu_reset(cs); - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 tcc->parent_realize(dev, errp); } diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c index 68f978d80b..0102f4ea79 100644 --- a/target/unicore32/cpu.c +++ b/target/unicore32/cpu.c @@ -96,7 +96,11 @@ static void uc32_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 ucc->parent_realize(dev, errp); } diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index 590813d4f7..b6740c0d66 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -131,7 +131,11 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Err= or **errp) =20 cs->gdb_num_regs =3D xcc->config->gdb_regmap.num_regs; =20 - qemu_init_vcpu(cs); + qemu_init_vcpu(cs, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 xcc->parent_realize(dev, errp); } --=20 2.13.7 From nobody Wed Nov 5 16:45:31 2025 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536059516323682.3711456338743; Tue, 4 Sep 2018 04:11:56 -0700 (PDT) Received: from localhost ([::1]:50250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9FP-0003fk-9V for importer@patchew.org; Tue, 04 Sep 2018 07:11:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9DL-0001UG-1E for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fx9DK-0006TG-0J for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:43 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:47949) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fx9DJ-0006Rj-Lt for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:41 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 04 Sep 2018 13:09:39 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 19:08:21 +0800 Message-Id: <20180904110822.12863-5-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904110822.12863-1-fli@suse.com> References: <20180904110822.12863-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH 4/5] qemu_thread_create: propagate the error to callers to check 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: fli@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a new Error paramater for qemu_thread_create() to indicate if it succeeds rather than failing with an error. And propagate the error to let the callers check it. Besides, directly return if thread->data is NULL to avoid the segmentation fault in qemu_thread_join in qemu-thread-win32.c. Signed-off-by: Fei Li --- include/qemu/thread.h | 2 +- util/qemu-thread-posix.c | 15 +++++++++++---- util/qemu-thread-win32.c | 12 +++++++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/qemu/thread.h b/include/qemu/thread.h index dacebcfff0..71d8be5851 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -137,7 +137,7 @@ void qemu_event_destroy(QemuEvent *ev); =20 void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), - void *arg, int mode); + void *arg, int mode, Error **errp); void *qemu_thread_join(QemuThread *thread); void qemu_thread_get_self(QemuThread *thread); bool qemu_thread_is_self(QemuThread *thread); diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index dfa66ff2fb..a31c00abfd 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -15,6 +15,7 @@ #include "qemu/atomic.h" #include "qemu/notify.h" #include "qemu-thread-common.h" +#include "qapi/error.h" =20 static bool name_threads; =20 @@ -506,16 +507,17 @@ static void *qemu_thread_start(void *args) =20 void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void*), - void *arg, int mode) + void *arg, int mode, Error **errp) { sigset_t set, oldset; int err; pthread_attr_t attr; QemuThreadArgs *qemu_thread_args; + Error *local_err =3D NULL; =20 err =3D pthread_attr_init(&attr); if (err) { - error_exit(err, __func__); + goto fail; } =20 if (mode =3D=3D QEMU_THREAD_DETACHED) { @@ -534,12 +536,17 @@ void qemu_thread_create(QemuThread *thread, const cha= r *name, err =3D pthread_create(&thread->thread, &attr, qemu_thread_start, qemu_thread_args); =20 - if (err) - error_exit(err, __func__); + if (err) { + goto fail; + } =20 pthread_sigmask(SIG_SETMASK, &oldset, NULL); =20 pthread_attr_destroy(&attr); + return; +fail: + error_setg(&local_err, "%s", strerror(err)); + error_propagate(errp, local_err); } =20 void qemu_thread_get_self(QemuThread *thread) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 4a363ca675..725200abc9 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -20,6 +20,7 @@ #include "qemu/thread.h" #include "qemu/notify.h" #include "qemu-thread-common.h" +#include "qapi/error.h" #include =20 static bool name_threads; @@ -366,7 +367,7 @@ void *qemu_thread_join(QemuThread *thread) HANDLE handle; =20 data =3D thread->data; - if (data->mode =3D=3D QEMU_THREAD_DETACHED) { + if (data =3D=3D NULL || data->mode =3D=3D QEMU_THREAD_DETACHED) { return NULL; } =20 @@ -390,10 +391,11 @@ void *qemu_thread_join(QemuThread *thread) =20 void qemu_thread_create(QemuThread *thread, const char *name, void *(*start_routine)(void *), - void *arg, int mode) + void *arg, int mode, Error **errp) { HANDLE hThread; struct QemuThreadData *data; + Error *local_err =3D NULL; =20 data =3D g_malloc(sizeof *data); data->start_routine =3D start_routine; @@ -409,7 +411,11 @@ void qemu_thread_create(QemuThread *thread, const char= *name, hThread =3D (HANDLE) _beginthreadex(NULL, 0, win32_start_routine, data, 0, &thread->tid); if (!hThread) { - error_exit(GetLastError(), __func__); + error_setg_win32(&local_err, GetLastError(), + "failed to creat win32_start_routine"); + g_free(data); + error_propagate(errp, local_err); + return; } CloseHandle(hThread); thread->data =3D data; --=20 2.13.7 From nobody Wed Nov 5 16:45:31 2025 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; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1536059657501903.4293134873709; Tue, 4 Sep 2018 04:14:17 -0700 (PDT) Received: from localhost ([::1]:50262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9Hk-0006Zm-4h for importer@patchew.org; Tue, 04 Sep 2018 07:14:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50350) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fx9DO-0001kX-Ru for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fx9DM-0006WH-Db for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:46 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:42336) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fx9DL-0006Ug-W1 for qemu-devel@nongnu.org; Tue, 04 Sep 2018 07:09:44 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 04 Sep 2018 13:09:40 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Tue, 4 Sep 2018 19:08:22 +0800 Message-Id: <20180904110822.12863-6-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180904110822.12863-1-fli@suse.com> References: <20180904110822.12863-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH 5/5] Propagate qemu_thread_create's error to all callers to handle 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: fli@suse.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Let's propagate qemu_thread_create's error to make all callers check it. For those critical callers, just pass the &error_abort. Signed-off-by: Fei Li --- cpus.c | 48 ++++++++++++++++++++++++++++++++++++++---= ---- dump.c | 6 +++++- hw/misc/edu.c | 8 +++++++- hw/ppc/spapr_hcall.c | 9 ++++++++- hw/rdma/rdma_backend.c | 3 ++- hw/usb/ccid-card-emulated.c | 13 ++++++++++-- io/task.c | 3 ++- iothread.c | 15 +++++++++----- migration/migration.c | 47 ++++++++++++++++++++++++++++++++---------= --- migration/postcopy-ram.c | 11 ++++++++++- migration/ram.c | 32 ++++++++++++++++++++++++++---- migration/savevm.c | 8 +++++++- tests/atomic_add-bench.c | 3 ++- tests/iothread.c | 2 +- tests/qht-bench.c | 3 ++- tests/rcutorture.c | 3 ++- tests/test-aio.c | 2 +- tests/test-rcu-list.c | 3 ++- ui/vnc-jobs.c | 11 +++++++++-- util/compatfd.c | 8 +++++++- util/oslib-posix.c | 10 +++++++++- util/rcu.c | 3 ++- util/thread-pool.c | 4 +++- 23 files changed, 206 insertions(+), 49 deletions(-) diff --git a/cpus.c b/cpus.c index 41efddc218..24159af1e6 100644 --- a/cpus.c +++ b/cpus.c @@ -1904,6 +1904,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu, Error *= *errp) static QemuCond *single_tcg_halt_cond; static QemuThread *single_tcg_cpu_thread; static int tcg_region_inited; + Error *local_err =3D NULL; =20 assert(tcg_enabled()); /* @@ -1929,14 +1930,22 @@ static void qemu_tcg_init_vcpu(CPUState *cpu, Error= **errp) cpu->cpu_index); =20 qemu_thread_create(cpu->thread, thread_name, qemu_tcg_cpu_thre= ad_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 } else { /* share a single thread for all cpus with TCG */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); qemu_thread_create(cpu->thread, thread_name, qemu_tcg_rr_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 single_tcg_halt_cond =3D cpu->halt_cond; single_tcg_cpu_thread =3D cpu->thread; @@ -1957,6 +1966,7 @@ static void qemu_tcg_init_vcpu(CPUState *cpu, Error *= *errp) static void qemu_hax_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; + Error *local_err =3D NULL; =20 cpu->thread =3D g_malloc0(sizeof(QemuThread)); cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); @@ -1965,7 +1975,11 @@ static void qemu_hax_start_vcpu(CPUState *cpu, Error= **errp) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_hax_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #endif @@ -1974,6 +1988,7 @@ static void qemu_hax_start_vcpu(CPUState *cpu, Error = **errp) static void qemu_kvm_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; + Error *local_err =3D NULL; =20 cpu->thread =3D g_malloc0(sizeof(QemuThread)); cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); @@ -1981,12 +1996,17 @@ static void qemu_kvm_start_vcpu(CPUState *cpu, Erro= r **errp) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_kvm_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 static void qemu_hvf_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; + Error *local_err =3D NULL; =20 /* HVF currently does not support TCG, and only runs in * unrestricted-guest mode. */ @@ -1999,12 +2019,17 @@ static void qemu_hvf_start_vcpu(CPUState *cpu, Erro= r **errp) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 static void qemu_whpx_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; + Error *local_err =3D NULL; =20 cpu->thread =3D g_malloc0(sizeof(QemuThread)); cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); @@ -2012,7 +2037,11 @@ static void qemu_whpx_start_vcpu(CPUState *cpu, Erro= r **errp) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #endif @@ -2021,6 +2050,7 @@ static void qemu_whpx_start_vcpu(CPUState *cpu, Error= **errp) static void qemu_dummy_start_vcpu(CPUState *cpu, Error **errp) { char thread_name[VCPU_THREAD_NAME_SIZE]; + Error *local_err =3D NULL; =20 cpu->thread =3D g_malloc0(sizeof(QemuThread)); cpu->halt_cond =3D g_malloc0(sizeof(QemuCond)); @@ -2028,7 +2058,11 @@ static void qemu_dummy_start_vcpu(CPUState *cpu, Err= or **errp) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", cpu->cpu_index); qemu_thread_create(cpu->thread, thread_name, qemu_dummy_cpu_thread_fn,= cpu, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 void qemu_init_vcpu(CPUState *cpu, Error **errp) diff --git a/dump.c b/dump.c index 500b554523..82d343f0e7 100644 --- a/dump.c +++ b/dump.c @@ -2022,7 +2022,11 @@ void qmp_dump_guest_memory(bool paging, const char *= file, /* detached dump */ s->detached =3D true; qemu_thread_create(&s->dump_thread, "dump_thread", dump_thread, - s, QEMU_THREAD_DETACHED); + s, QEMU_THREAD_DETACHED, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } else { /* sync dump */ dump_process(s, errp); diff --git a/hw/misc/edu.c b/hw/misc/edu.c index df26a4d046..d884ee99ce 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -29,6 +29,7 @@ #include "qemu/timer.h" #include "qemu/main-loop.h" /* iothread mutex */ #include "qapi/visitor.h" +#include "qapi/error.h" =20 #define EDU(obj) OBJECT_CHECK(EduState, obj, "edu") =20 @@ -343,6 +344,7 @@ static void pci_edu_realize(PCIDevice *pdev, Error **er= rp) { EduState *edu =3D DO_UPCAST(EduState, pdev, pdev); uint8_t *pci_conf =3D pdev->config; + Error *local_err =3D NULL; =20 pci_config_set_interrupt_pin(pci_conf, 1); =20 @@ -355,7 +357,11 @@ static void pci_edu_realize(PCIDevice *pdev, Error **e= rrp) qemu_mutex_init(&edu->thr_mutex); qemu_cond_init(&edu->thr_cond); qemu_thread_create(&edu->thread, "edu", edu_fact_thread, - edu, QEMU_THREAD_JOINABLE); + edu, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } =20 memory_region_init_io(&edu->mmio, OBJECT(edu), &edu_mmio_ops, edu, "edu-mmio", 1 * MiB); diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index ae913d070f..07d857410f 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -478,6 +478,7 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *cp= u, sPAPRPendingHPT *pending =3D spapr->pending_hpt; uint64_t current_ram_size; int rc; + Error *local_err =3D NULL; =20 if (spapr->resize_hpt =3D=3D SPAPR_RESIZE_HPT_DISABLED) { return H_AUTHORITY; @@ -539,7 +540,13 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *c= pu, pending->ret =3D H_HARDWARE; =20 qemu_thread_create(&pending->thread, "sPAPR HPT prepare", - hpt_prepare_thread, pending, QEMU_THREAD_DETACHED); + hpt_prepare_thread, pending, + QEMU_THREAD_DETACHED, &local_err); + if (local_err) { + error_reportf_err(error_in, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + return H_RESOURCE; + } =20 spapr->pending_hpt =3D pending; =20 diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index d7a4bbd91f..e7cbb0c368 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -165,7 +165,8 @@ static void start_comp_thread(RdmaBackendDev *backend_d= ev) ibv_get_device_name(backend_dev->ib_dev)); backend_dev->comp_thread.run =3D true; qemu_thread_create(&backend_dev->comp_thread.thread, thread_name, - comp_handler_thread, backend_dev, QEMU_THREAD_DETAC= HED); + comp_handler_thread, backend_dev, + QEMU_THREAD_DETACHED, &error_abort); } =20 void rdma_backend_register_comp_handler(void (*handler)(int status, diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index 5c8b3c9907..8f73f73ca4 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -483,6 +483,7 @@ static void emulated_realize(CCIDCardState *base, Error= **errp) EmulatedState *card =3D EMULATED_CCID_CARD(base); VCardEmulError ret; const EnumTable *ptable; + Error *local_err =3D NULL; =20 QSIMPLEQ_INIT(&card->event_list); QSIMPLEQ_INIT(&card->guest_apdu_list); @@ -539,9 +540,17 @@ static void emulated_realize(CCIDCardState *base, Erro= r **errp) return; } qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, - card, QEMU_THREAD_JOINABLE); + card, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thr= ead, - card, QEMU_THREAD_JOINABLE); + card, QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 static void emulated_unrealize(CCIDCardState *base, Error **errp) diff --git a/io/task.c b/io/task.c index 2886a2c1bc..6d3a18ab80 100644 --- a/io/task.c +++ b/io/task.c @@ -149,7 +149,8 @@ void qio_task_run_in_thread(QIOTask *task, "io-task-worker", qio_task_thread_worker, data, - QEMU_THREAD_DETACHED); + QEMU_THREAD_DETACHED, + &error_abort); } =20 =20 diff --git a/iothread.c b/iothread.c index aff1281257..b19e548e5b 100644 --- a/iothread.c +++ b/iothread.c @@ -160,10 +160,7 @@ static void iothread_complete(UserCreatable *obj, Erro= r **errp) iothread->poll_shrink, &local_error); if (local_error) { - error_propagate(errp, local_error); - aio_context_unref(iothread->ctx); - iothread->ctx =3D NULL; - return; + goto fail; } =20 qemu_mutex_init(&iothread->init_done_lock); @@ -176,9 +173,12 @@ static void iothread_complete(UserCreatable *obj, Erro= r **errp) name =3D object_get_canonical_path_component(OBJECT(obj)); thread_name =3D g_strdup_printf("IO %s", name); qemu_thread_create(&iothread->thread, thread_name, iothread_run, - iothread, QEMU_THREAD_JOINABLE); + iothread, QEMU_THREAD_JOINABLE, &local_error); g_free(thread_name); g_free(name); + if (local_error) { + goto fail; + } =20 /* Wait for initialization to complete */ qemu_mutex_lock(&iothread->init_done_lock); @@ -187,6 +187,11 @@ static void iothread_complete(UserCreatable *obj, Erro= r **errp) &iothread->init_done_lock); } qemu_mutex_unlock(&iothread->init_done_lock); + return; +fail: + error_propagate(errp, local_error); + aio_context_unref(iothread->ctx); + iothread->ctx =3D NULL; } =20 typedef struct { diff --git a/migration/migration.c b/migration/migration.c index 4b316ec343..34af7b82b9 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -388,6 +388,7 @@ static void process_incoming_migration_co(void *opaque) MigrationIncomingState *mis =3D migration_incoming_get_current(); PostcopyState ps; int ret; + Error *local_err =3D NULL; =20 assert(mis->from_src_file); mis->migration_incoming_co =3D qemu_coroutine_self(); @@ -421,7 +422,13 @@ static void process_incoming_migration_co(void *opaque) /* we get COLO info, and know if we are in COLO mode */ if (!ret && migration_incoming_enable_colo()) { qemu_thread_create(&mis->colo_incoming_thread, "COLO incoming", - colo_process_incoming_thread, mis, QEMU_THREAD_JOINABLE); + colo_process_incoming_thread, mis, + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + goto fail; + } mis->have_colo_incoming_thread =3D true; qemu_coroutine_yield(); =20 @@ -430,20 +437,22 @@ static void process_incoming_migration_co(void *opaqu= e) } =20 if (ret < 0) { - Error *local_err =3D NULL; - - migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); error_report("load of migration failed: %s", strerror(-ret)); - qemu_fclose(mis->from_src_file); - if (multifd_load_cleanup(&local_err) !=3D 0) { - error_report_err(local_err); - } - exit(EXIT_FAILURE); + goto fail; } mis->bh =3D qemu_bh_new(process_incoming_migration_bh, mis); qemu_bh_schedule(mis->bh); mis->migration_incoming_co =3D NULL; + return; +fail: + local_err =3D NULL; + migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, + MIGRATION_STATUS_FAILED); + qemu_fclose(mis->from_src_file); + if (multifd_load_cleanup(&local_err) !=3D 0) { + error_report_err(local_err); + } + exit(EXIT_FAILURE); } =20 static void migration_incoming_setup(QEMUFile *f) @@ -2288,6 +2297,7 @@ out: static int open_return_path_on_source(MigrationState *ms, bool create_thread) { + Error *local_err =3D NULL; =20 ms->rp_state.from_dst_file =3D qemu_file_get_return_path(ms->to_dst_fi= le); if (!ms->rp_state.from_dst_file) { @@ -2302,7 +2312,13 @@ static int open_return_path_on_source(MigrationState= *ms, } =20 qemu_thread_create(&ms->rp_state.rp_thread, "return path", - source_return_path_thread, ms, QEMU_THREAD_JOINABLE= ); + source_return_path_thread, ms, + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + return -1; + } =20 trace_open_return_path_on_source_continue(); =20 @@ -3128,7 +3144,14 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) return; } qemu_thread_create(&s->thread, "live_migration", migration_thread, s, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_in); + if (error_in) { + error_reportf_err(error_in, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); + migrate_fd_cleanup(s); + return; + } s->migration_thread_running =3D true; } =20 diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 853d8b32ca..85d9114bd1 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1082,6 +1082,8 @@ retry: =20 int postcopy_ram_enable_notify(MigrationIncomingState *mis) { + Error *local_err =3D NULL; + /* Open the fd for the kernel to give us userfaults */ mis->userfault_fd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK= ); if (mis->userfault_fd =3D=3D -1) { @@ -1109,7 +1111,14 @@ int postcopy_ram_enable_notify(MigrationIncomingStat= e *mis) =20 qemu_sem_init(&mis->fault_thread_sem, 0); qemu_thread_create(&mis->fault_thread, "postcopy/fault", - postcopy_ram_fault_thread, mis, QEMU_THREAD_JOINABL= E); + postcopy_ram_fault_thread, mis, + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + qemu_sem_destroy(&mis->fault_thread_sem); + return -1; + } qemu_sem_wait(&mis->fault_thread_sem); qemu_sem_destroy(&mis->fault_thread_sem); mis->have_fault_thread =3D true; diff --git a/migration/ram.c b/migration/ram.c index 79c89425a3..ebbd21f8c2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -470,6 +470,7 @@ static void compress_threads_save_cleanup(void) static int compress_threads_save_setup(void) { int i, thread_count; + Error *local_err =3D NULL; =20 if (!migrate_use_compression()) { return 0; @@ -501,7 +502,12 @@ static int compress_threads_save_setup(void) qemu_cond_init(&comp_param[i].cond); qemu_thread_create(compress_threads + i, "compress", do_data_compress, comp_param + i, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + goto exit; + } } return 0; =20 @@ -1076,7 +1082,13 @@ static void multifd_new_send_channel_async(QIOTask *= task, gpointer opaque) qio_channel_set_delay(p->c, false); p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + migrate_set_error(migrate_get_current(), local_err); + return; + } =20 atomic_inc(&multifd_send_state->count); } @@ -1346,7 +1358,13 @@ bool multifd_recv_new_channel(QIOChannel *ioc) =20 p->running =3D true; qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + multifd_recv_terminate_threads(local_err); + return false; + } atomic_inc(&multifd_recv_state->count); return multifd_recv_state->count =3D=3D migrate_multifd_channels(); } @@ -3542,6 +3560,7 @@ static void compress_threads_load_cleanup(void) static int compress_threads_load_setup(QEMUFile *f) { int i, thread_count; + Error *local_err =3D NULL; =20 if (!migrate_use_compression()) { return 0; @@ -3565,7 +3584,12 @@ static int compress_threads_load_setup(QEMUFile *f) decomp_param[i].quit =3D false; qemu_thread_create(decompress_threads + i, "decompress", do_data_decompress, decomp_param + i, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + goto exit; + } } return 0; exit: diff --git a/migration/savevm.c b/migration/savevm.c index 13e51f0e34..31973312cf 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1729,7 +1729,13 @@ static int loadvm_postcopy_handle_listen(MigrationIn= comingState *mis) qemu_sem_init(&mis->listen_thread_sem, 0); qemu_thread_create(&mis->listen_thread, "postcopy/listen", postcopy_ram_listen_thread, NULL, - QEMU_THREAD_DETACHED); + QEMU_THREAD_DETACHED, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + qemu_sem_destroy(&mis->listen_thread_sem); + return -1; + } qemu_sem_wait(&mis->listen_thread_sem); qemu_sem_destroy(&mis->listen_thread_sem); =20 diff --git a/tests/atomic_add-bench.c b/tests/atomic_add-bench.c index 2f6c72f63a..338b9563e3 100644 --- a/tests/atomic_add-bench.c +++ b/tests/atomic_add-bench.c @@ -2,6 +2,7 @@ #include "qemu/thread.h" #include "qemu/host-utils.h" #include "qemu/processor.h" +#include "qapi/error.h" =20 struct thread_info { uint64_t r; @@ -110,7 +111,7 @@ static void create_threads(void) =20 info->r =3D (i + 1) ^ time(NULL); qemu_thread_create(&threads[i], NULL, thread_func, info, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); } } =20 diff --git a/tests/iothread.c b/tests/iothread.c index 777d9eea46..f4ad992e61 100644 --- a/tests/iothread.c +++ b/tests/iothread.c @@ -73,7 +73,7 @@ IOThread *iothread_new(void) qemu_mutex_init(&iothread->init_done_lock); qemu_cond_init(&iothread->init_done_cond); qemu_thread_create(&iothread->thread, NULL, iothread_run, - iothread, QEMU_THREAD_JOINABLE); + iothread, QEMU_THREAD_JOINABLE, &error_abort); =20 /* Wait for initialization to complete */ qemu_mutex_lock(&iothread->init_done_lock); diff --git a/tests/qht-bench.c b/tests/qht-bench.c index f492b3a20a..20a4101a17 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -9,6 +9,7 @@ #include "qemu/atomic.h" #include "qemu/qht.h" #include "qemu/rcu.h" +#include "qapi/error.h" #include "exec/tb-hash-xx.h" =20 struct thread_stats { @@ -239,7 +240,7 @@ th_create_n(QemuThread **threads, struct thread_info **= infos, const char *name, prepare_thread_info(&info[i], offset + i); info[i].func =3D func; qemu_thread_create(&th[i], name, thread_func, &info[i], - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); } } =20 diff --git a/tests/rcutorture.c b/tests/rcutorture.c index 49311c82ea..0e799ff256 100644 --- a/tests/rcutorture.c +++ b/tests/rcutorture.c @@ -64,6 +64,7 @@ #include "qemu/atomic.h" #include "qemu/rcu.h" #include "qemu/thread.h" +#include "qapi/error.h" =20 long long n_reads =3D 0LL; long n_updates =3D 0L; @@ -90,7 +91,7 @@ static void create_thread(void *(*func)(void *)) exit(-1); } qemu_thread_create(&threads[n_threads], "test", func, &data[n_threads], - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); n_threads++; } =20 diff --git a/tests/test-aio.c b/tests/test-aio.c index 86fb73b3d5..b3ac261724 100644 --- a/tests/test-aio.c +++ b/tests/test-aio.c @@ -154,7 +154,7 @@ static void test_acquire(void) =20 qemu_thread_create(&thread, "test_acquire_thread", test_acquire_thread, - &data, QEMU_THREAD_JOINABLE); + &data, QEMU_THREAD_JOINABLE, &error_abort); =20 /* Block in aio_poll(), let other thread kick us and acquire context */ aio_context_acquire(ctx); diff --git a/tests/test-rcu-list.c b/tests/test-rcu-list.c index 192bfbf02e..9ea35a3dad 100644 --- a/tests/test-rcu-list.c +++ b/tests/test-rcu-list.c @@ -25,6 +25,7 @@ #include "qemu/rcu.h" #include "qemu/thread.h" #include "qemu/rcu_queue.h" +#include "qapi/error.h" =20 /* * Test variables. @@ -68,7 +69,7 @@ static void create_thread(void *(*func)(void *)) exit(-1); } qemu_thread_create(&threads[n_threads], "test", func, &data[n_threads], - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); n_threads++; } =20 diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index 7c05a1e6df..60d5ceb6a8 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -31,6 +31,7 @@ #include "vnc-jobs.h" #include "qemu/sockets.h" #include "qemu/main-loop.h" +#include "qapi/error.h" #include "block/aio.h" =20 /* @@ -333,13 +334,19 @@ static bool vnc_worker_thread_running(void) =20 void vnc_start_worker_thread(Error **errp) { + Error *local_err =3D NULL; + VncJobQueue *q; =20 if (vnc_worker_thread_running()) - return ; + return; =20 q =3D vnc_queue_init(); qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, q, - QEMU_THREAD_DETACHED); + QEMU_THREAD_DETACHED, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } queue =3D q; /* Set global queue */ } diff --git a/util/compatfd.c b/util/compatfd.c index 65501de622..b3d3c82266 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -71,6 +71,7 @@ static int qemu_signalfd_compat(const sigset_t *mask, Err= or **errp) struct sigfd_compat_info *info; QemuThread thread; int fds[2]; + Error *local_err =3D NULL; =20 info =3D malloc(sizeof(*info)); if (info =3D=3D NULL) { @@ -92,7 +93,12 @@ static int qemu_signalfd_compat(const sigset_t *mask, Er= ror **errp) info->fd =3D fds[1]; =20 qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, info, - QEMU_THREAD_DETACHED); + QEMU_THREAD_DETACHED, &local_err); + if (local_err) { + error_propagate(errp, local_err); + free(info); + return -1; + } =20 return fds[0]; } diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 13b6f8d776..91a7921a57 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -364,6 +364,7 @@ static bool touch_all_pages(char *area, size_t hpagesiz= e, size_t numpages, size_t size_per_thread; char *addr =3D area; int i =3D 0; + Error *local_err =3D NULL; =20 memset_thread_failed =3D false; memset_num_threads =3D get_memset_num_threads(smp_cpus); @@ -377,13 +378,20 @@ static bool touch_all_pages(char *area, size_t hpages= ize, size_t numpages, memset_thread[i].hpagesize =3D hpagesize; qemu_thread_create(&memset_thread[i].pgthread, "touch_pages", do_touch_pages, &memset_thread[i], - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &local_err); + if (local_err) { + error_reportf_err(local_err, "Failed in %s() when calls " + "qemu_thread_create(): \n", __func__); + memset_thread_failed =3D true; + goto out; + } addr +=3D size_per_thread; numpages -=3D numpages_per_thread; } for (i =3D 0; i < memset_num_threads; i++) { qemu_thread_join(&memset_thread[i].pgthread); } +out: g_free(memset_thread); memset_thread =3D NULL; =20 diff --git a/util/rcu.c b/util/rcu.c index 5676c22bd1..145dcdb0c6 100644 --- a/util/rcu.c +++ b/util/rcu.c @@ -32,6 +32,7 @@ #include "qemu/atomic.h" #include "qemu/thread.h" #include "qemu/main-loop.h" +#include "qapi/error.h" #if defined(CONFIG_MALLOC_TRIM) #include #endif @@ -325,7 +326,7 @@ static void rcu_init_complete(void) * must have been quiescent even after forking, just recreate it. */ qemu_thread_create(&thread, "call_rcu", call_rcu_thread, - NULL, QEMU_THREAD_DETACHED); + NULL, QEMU_THREAD_DETACHED, &error_abort); =20 rcu_register_thread(); } diff --git a/util/thread-pool.c b/util/thread-pool.c index 610646d131..ad0f980783 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -22,6 +22,7 @@ #include "trace.h" #include "block/thread-pool.h" #include "qemu/main-loop.h" +#include "qapi/error.h" =20 static void do_spawn_thread(ThreadPool *pool); =20 @@ -132,7 +133,8 @@ static void do_spawn_thread(ThreadPool *pool) pool->new_threads--; pool->pending_threads++; =20 - qemu_thread_create(&t, "worker", worker_thread, pool, QEMU_THREAD_DETA= CHED); + qemu_thread_create(&t, "worker", worker_thread, pool, + QEMU_THREAD_DETACHED, &error_abort); } =20 static void spawn_thread_bh_fn(void *opaque) --=20 2.13.7