From nobody Sat Apr 27 15:54:21 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; 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 1545746860311796.2886866933399; Tue, 25 Dec 2018 06:07:40 -0800 (PST) Received: from localhost ([127.0.0.1]:41488 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnMt-0002wZ-O2 for importer@patchew.org; Tue, 25 Dec 2018 09:07:35 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKl-0001Iq-B8 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKh-0003gB-Hl for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:23 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:33263) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKg-0003e9-8U for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:19 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:12 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:34 +0800 Message-Id: <20181225140449.15786-2-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 01/16] 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: lifei1214@126.com, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When qemu_signal_init() fails in qemu_init_main_loop(), we return without setting an error. Its callers crash then when they try to report the error with error_report_err(). To avoid such segmentation fault, add a new Error parameter to make the call trace to propagate the err to the final caller. Fixes: 2f78e491d7b46542158ce0b8132ee4e05bc0ade4 Cc: Paolo Bonzini Signed-off-by: Fei Li Reviewed-by: Fam Zheng Reviewed-by: Markus Armbruster --- util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/main-loop.c b/util/main-loop.c index affe0403c5..443cb4cfe8 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -71,7 +71,7 @@ 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; @@ -96,7 +96,7 @@ static int qemu_signal_init(void) sigdelset(&set, SIG_IPI); sigfd =3D qemu_signalfd(&set); if (sigfd =3D=3D -1) { - fprintf(stderr, "failed to create signalfd\n"); + error_setg_errno(errp, errno, "failed to create signalfd"); return -errno; } =20 @@ -109,7 +109,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,7 +148,7 @@ 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(errp); if (ret) { return ret; } --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747040345264.2316048212052; Tue, 25 Dec 2018 06:10:40 -0800 (PST) Received: from localhost ([127.0.0.1]:41511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnPq-0006Me-SK for importer@patchew.org; Tue, 25 Dec 2018 09:10:38 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKl-0001Ir-BB for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKj-0003hF-D0 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:23 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:41604) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKh-0003fS-JY for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:20 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:15 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:35 +0800 Message-Id: <20181225140449.15786-3-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 02/16] migration: fix the multifd code when receiving less channels 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: lifei1214@126.com, "Dr . David Alan Gilbert" , Peter Xu , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In our current code, when multifd is used during migration, if there is an error before the destination receives all new channels, the source keeps running, however the destination does not exit but keeps waiting until the source is killed deliberately. Fix this by dumping the specific error and let users decide whether to quit from the destination side when failing to receive packet via some channel. And update the comment for multifd_recv_new_channel(). Cc: Dr. David Alan Gilbert Cc: Peter Xu Cc: Markus Armbruster Signed-off-by: Fei Li Reviewed-by: Peter Xu --- migration/channel.c | 11 ++++++----- migration/migration.c | 9 +++++++-- migration/migration.h | 2 +- migration/ram.c | 17 ++++++++++++++--- migration/ram.h | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/migration/channel.c b/migration/channel.c index 33e0e9b82f..20e4c8e2dc 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -30,6 +30,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) { MigrationState *s =3D migrate_get_current(); + Error *local_err =3D NULL; =20 trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); @@ -38,13 +39,13 @@ void migration_channel_process_incoming(QIOChannel *ioc) *s->parameters.tls_creds && !object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { - Error *local_err =3D NULL; migration_tls_channel_process_incoming(s, ioc, &local_err); - if (local_err) { - error_report_err(local_err); - } } else { - migration_ioc_process_incoming(ioc); + migration_ioc_process_incoming(ioc, &local_err); + } + + if (local_err) { + error_report_err(local_err); } } =20 diff --git a/migration/migration.c b/migration/migration.c index ffc4d9e556..24cb4b9d0d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -541,7 +541,7 @@ void migration_fd_process_incoming(QEMUFile *f) migration_incoming_process(); } =20 -void migration_ioc_process_incoming(QIOChannel *ioc) +void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); bool start_migration; @@ -563,9 +563,14 @@ void migration_ioc_process_incoming(QIOChannel *ioc) */ start_migration =3D !migrate_use_multifd(); } else { + Error *local_err =3D NULL; /* Multiple connections */ assert(migrate_use_multifd()); - start_migration =3D multifd_recv_new_channel(ioc); + start_migration =3D multifd_recv_new_channel(ioc, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } } =20 if (start_migration) { diff --git a/migration/migration.h b/migration/migration.h index e413d4d8b6..02b7304610 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -229,7 +229,7 @@ struct MigrationState void migrate_set_state(int *state, int old_state, int new_state); =20 void migration_fd_process_incoming(QEMUFile *f); -void migration_ioc_process_incoming(QIOChannel *ioc); +void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp); void migration_incoming_process(void); =20 bool migration_has_all_channels(void); diff --git a/migration/ram.c b/migration/ram.c index 7e7deec4d8..1671dedc97 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1322,8 +1322,13 @@ bool multifd_recv_all_channels_created(void) return thread_count =3D=3D atomic_read(&multifd_recv_state->count); } =20 -/* Return true if multifd is ready for the migration, otherwise false */ -bool multifd_recv_new_channel(QIOChannel *ioc) +/* + * Try to receive all multifd channels to get ready for the migration. + * - Return true and do not set @errp when correctly receving all channels; + * - Return false and do not set @errp when correctly receiving the curren= t one; + * - Return false and set @errp when failing to receive the current channe= l. + */ +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; @@ -1332,6 +1337,10 @@ bool multifd_recv_new_channel(QIOChannel *ioc) id =3D multifd_recv_initial_packet(ioc, &local_err); if (id < 0) { multifd_recv_terminate_threads(local_err); + error_propagate_prepend(errp, local_err, + "failed to receive packet" + " via multifd channel %d: ", + atomic_read(&multifd_recv_state->count)); return false; } =20 @@ -1340,6 +1349,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc) error_setg(&local_err, "multifd: received id '%d' already setup'", id); multifd_recv_terminate_threads(local_err); + error_propagate(errp, local_err); return false; } p->c =3D ioc; @@ -1351,7 +1361,8 @@ bool multifd_recv_new_channel(QIOChannel *ioc) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); atomic_inc(&multifd_recv_state->count); - return multifd_recv_state->count =3D=3D migrate_multifd_channels(); + return atomic_read(&multifd_recv_state->count) =3D=3D + migrate_multifd_channels(); } =20 /** diff --git a/migration/ram.h b/migration/ram.h index 83ff1bc11a..046d3074be 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -47,7 +47,7 @@ int multifd_save_cleanup(Error **errp); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); bool multifd_recv_all_channels_created(void); -bool multifd_recv_new_channel(QIOChannel *ioc); +bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); =20 uint64_t ram_pagesize_summary(void); int ram_save_queue_pages(const char *rbname, ram_addr_t start, ram_addr_t = len); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747214241863.6936543928814; Tue, 25 Dec 2018 06:13:34 -0800 (PST) Received: from localhost ([127.0.0.1]:41543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnSZ-0001Vs-FY for importer@patchew.org; Tue, 25 Dec 2018 09:13:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33133) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKn-0001J5-8G for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKl-0003jX-9H for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:25 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:49149) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKj-0003gm-Fk for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:21 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:17 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:36 +0800 Message-Id: <20181225140449.15786-4-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 03/16] migration: remove unused &local_err parameter in multifd_save_cleanup 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: lifei1214@126.com, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Always call migrate_set_error() to set the error state without relying on whether multifd_save_cleanup() succeeds. As the passed &local_err is never used in multifd_save_cleanup(), remove it. And make the function be: void multifd_save_cleanup(void). Cc: Dr. David Alan Gilbert Signed-off-by: Fei Li Reviewed-by: Juan Quintela --- migration/migration.c | 5 +---- migration/ram.c | 11 ++++------- migration/ram.h | 2 +- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 24cb4b9d0d..5d322eb9d6 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1386,7 +1386,6 @@ static void migrate_fd_cleanup(void *opaque) qemu_savevm_state_cleanup(); =20 if (s->to_dst_file) { - Error *local_err =3D NULL; QEMUFile *tmp; =20 trace_migrate_fd_cleanup(); @@ -1397,9 +1396,7 @@ static void migrate_fd_cleanup(void *opaque) } qemu_mutex_lock_iothread(); =20 - if (multifd_save_cleanup(&local_err) !=3D 0) { - error_report_err(local_err); - } + multifd_save_cleanup(); qemu_mutex_lock(&s->qemu_file_lock); tmp =3D s->to_dst_file; s->to_dst_file =3D NULL; diff --git a/migration/ram.c b/migration/ram.c index 1671dedc97..435a8d2946 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -917,13 +917,12 @@ static void multifd_send_terminate_threads(Error *err) } } =20 -int multifd_save_cleanup(Error **errp) +void multifd_save_cleanup(void) { int i; - int ret =3D 0; =20 if (!migrate_use_multifd()) { - return 0; + return; } multifd_send_terminate_threads(NULL); for (i =3D 0; i < migrate_multifd_channels(); i++) { @@ -953,7 +952,6 @@ int multifd_save_cleanup(Error **errp) multifd_send_state->pages =3D NULL; g_free(multifd_send_state); multifd_send_state =3D NULL; - return ret; } =20 static void multifd_send_sync_main(void) @@ -1071,9 +1069,8 @@ static void multifd_new_send_channel_async(QIOTask *t= ask, gpointer opaque) Error *local_err =3D NULL; =20 if (qio_task_propagate_error(task, &local_err)) { - if (multifd_save_cleanup(&local_err) !=3D 0) { - migrate_set_error(migrate_get_current(), local_err); - } + migrate_set_error(migrate_get_current(), local_err); + multifd_save_cleanup(); } else { p->c =3D QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); diff --git a/migration/ram.h b/migration/ram.h index 046d3074be..936177b3e9 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -43,7 +43,7 @@ uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_total(void); =20 int multifd_save_setup(void); -int multifd_save_cleanup(Error **errp); +void multifd_save_cleanup(void); int multifd_load_setup(void); int multifd_load_cleanup(Error **errp); bool multifd_recv_all_channels_created(void); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545746866922264.7610616214496; Tue, 25 Dec 2018 06:07:46 -0800 (PST) Received: from localhost ([127.0.0.1]:41490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnMz-00034Y-7k for importer@patchew.org; Tue, 25 Dec 2018 09:07:41 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKu-0001Nt-8j for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKr-0003nK-1e for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:32 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:60781) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKn-0003in-7s for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:27 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:20 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:37 +0800 Message-Id: <20181225140449.15786-5-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 04/16] migration: add more error handling for postcopy_ram_enable_notify 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: lifei1214@126.com, "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Call postcopy_ram_incoming_cleanup() to do the cleanup when postcopy_ram_enable_notify fails. Besides, report the error message when qemu_ram_foreach_migratable_block() fails. Cc: Dr. David Alan Gilbert Signed-off-by: Fei Li Reviewed-by: Dr. David Alan Gilbert --- migration/postcopy-ram.c | 1 + migration/savevm.c | 1 + 2 files changed, 2 insertions(+) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index e5c02a32c5..fa09dba534 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1117,6 +1117,7 @@ int postcopy_ram_enable_notify(MigrationIncomingState= *mis) =20 /* Mark so that we get notified of accesses to unwritten areas */ if (qemu_ram_foreach_migratable_block(ram_block_enable_notify, mis)) { + error_report("ram_block_enable_notify failed"); return -1; } =20 diff --git a/migration/savevm.c b/migration/savevm.c index 9e45fb4f3f..d784e8aa40 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1729,6 +1729,7 @@ static int loadvm_postcopy_handle_listen(MigrationInc= omingState *mis) */ if (migrate_postcopy_ram()) { if (postcopy_ram_enable_notify(mis)) { + postcopy_ram_incoming_cleanup(mis); return -1; } } --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747045598559.9883121743056; Tue, 25 Dec 2018 06:10:45 -0800 (PST) Received: from localhost ([127.0.0.1]:41516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnPw-0006Ua-99 for importer@patchew.org; Tue, 25 Dec 2018 09:10:44 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKu-0001Ns-8b for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKr-0003o6-N1 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:32 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:60622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKr-0003lH-DH for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:29 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:22 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:38 +0800 Message-Id: <20181225140449.15786-6-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 05/16] migration: unify error handling for process_incoming_migration_co 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: lifei1214@126.com, Markus Armbruster , Peter Xu , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In the current code, if process_incoming_migration_co() fails we do the same error handing: set the error state, close the source file, do the cleanup for multifd, and then exit(EXIT_FAILURE). To make the code clearer, add a "goto fail" to unify the error handling. Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Cc: Peter Xu Signed-off-by: Fei Li Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5d322eb9d6..ded151b1bf 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -438,15 +438,13 @@ static void process_incoming_migration_co(void *opaqu= e) /* Make sure all file formats flush their mutable metadata */ bdrv_invalidate_cache_all(&local_err); if (local_err) { - migrate_set_state(&mis->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_FAILED); error_report_err(local_err); - exit(EXIT_FAILURE); + goto fail; } =20 if (colo_init_ram_cache() < 0) { error_report("Init ram cache failed"); - exit(EXIT_FAILURE); + goto fail; } =20 qemu_thread_create(&mis->colo_incoming_thread, "COLO incoming", @@ -461,20 +459,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) --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747474281119.56244881893986; Tue, 25 Dec 2018 06:17:54 -0800 (PST) Received: from localhost ([127.0.0.1]:41588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnWq-0006Pz-LO for importer@patchew.org; Tue, 25 Dec 2018 09:17:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKu-0001Nu-MF for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKr-0003oH-Pt for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:32 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:45646) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKr-0003mn-Br for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:29 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:24 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:39 +0800 Message-Id: <20181225140449.15786-7-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 06/16] qemu_thread: Make qemu_thread_create() handle errors properly 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: lifei1214@126.com, Paolo Bonzini , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qemu_thread_create() abort()s on error. Not nice. Give it a return value and an Error ** argument, so it can return success/failure. Considering qemu_thread_create() is quite widely used in qemu, split this into two steps: this patch passes the &error_abort to qemu_thread_create() everywhere, and the next 9 patches will improve on &error_abort for callers who need. Cc: Markus Armbruster Cc: Paolo Bonzini Signed-off-by: Fei Li --- cpus.c | 23 +++++++++++++++-------- dump.c | 3 ++- hw/misc/edu.c | 4 +++- hw/ppc/spapr_hcall.c | 4 +++- hw/rdma/rdma_backend.c | 3 ++- hw/usb/ccid-card-emulated.c | 5 +++-- include/qemu/thread.h | 4 ++-- io/task.c | 3 ++- iothread.c | 3 ++- migration/migration.c | 11 ++++++++--- migration/postcopy-ram.c | 4 +++- migration/ram.c | 12 ++++++++---- migration/savevm.c | 3 ++- 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 | 6 ++++-- util/compatfd.c | 6 ++++-- util/oslib-posix.c | 3 ++- util/qemu-thread-posix.c | 27 ++++++++++++++++++++------- util/qemu-thread-win32.c | 16 ++++++++++++---- util/rcu.c | 3 ++- util/thread-pool.c | 4 +++- 26 files changed, 112 insertions(+), 51 deletions(-) diff --git a/cpus.c b/cpus.c index 0ddeeefc14..25df03326b 100644 --- a/cpus.c +++ b/cpus.c @@ -1961,15 +1961,17 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); =20 + /* TODO: let the callers handle the error instead of abort() h= ere */ qemu_thread_create(cpu->thread, thread_name, qemu_tcg_cpu_thre= ad_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); =20 } else { /* share a single thread for all cpus with TCG */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); + /* TODO: let the callers handle the error instead of abort() h= ere */ qemu_thread_create(cpu->thread, thread_name, qemu_tcg_rr_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); =20 single_tcg_halt_cond =3D cpu->halt_cond; single_tcg_cpu_thread =3D cpu->thread; @@ -1997,8 +1999,9 @@ static void qemu_hax_start_vcpu(CPUState *cpu) =20 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX", cpu->cpu_index); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(cpu->thread, thread_name, qemu_hax_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #endif @@ -2013,8 +2016,9 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", cpu->cpu_index); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(cpu->thread, thread_name, qemu_kvm_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); } =20 static void qemu_hvf_start_vcpu(CPUState *cpu) @@ -2031,8 +2035,9 @@ static void qemu_hvf_start_vcpu(CPUState *cpu) =20 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", cpu->cpu_index); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); } =20 static void qemu_whpx_start_vcpu(CPUState *cpu) @@ -2044,8 +2049,9 @@ static void qemu_whpx_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE); + cpu, QEMU_THREAD_JOINABLE, &error_abort); #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #endif @@ -2060,8 +2066,9 @@ static void qemu_dummy_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); 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); + /* TODO: let the further caller handle the error instead of abort() he= re */ + qemu_thread_create(cpu->thread, thread_name, qemu_dummy_cpu_thread_fn, + cpu, QEMU_THREAD_JOINABLE, &error_abort); } =20 void qemu_init_vcpu(CPUState *cpu) diff --git a/dump.c b/dump.c index 4ec94c5e25..c35d6ddd22 100644 --- a/dump.c +++ b/dump.c @@ -2020,8 +2020,9 @@ void qmp_dump_guest_memory(bool paging, const char *f= ile, if (detach_p) { /* detached dump */ s->detached =3D true; + /* TODO: let the further caller handle the error instead of abort(= ) */ qemu_thread_create(&s->dump_thread, "dump_thread", dump_thread, - s, QEMU_THREAD_DETACHED); + s, QEMU_THREAD_DETACHED, &error_abort); } else { /* sync dump */ dump_process(s, errp); diff --git a/hw/misc/edu.c b/hw/misc/edu.c index cdcf550dd7..3f4ba7ded3 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -28,6 +28,7 @@ #include "hw/pci/msi.h" #include "qemu/timer.h" #include "qemu/main-loop.h" /* iothread mutex */ +#include "qapi/error.h" #include "qapi/visitor.h" =20 #define TYPE_PCI_EDU_DEVICE "edu" @@ -355,8 +356,9 @@ static void pci_edu_realize(PCIDevice *pdev, Error **er= rp) =20 qemu_mutex_init(&edu->thr_mutex); qemu_cond_init(&edu->thr_cond); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&edu->thread, "edu", edu_fact_thread, - edu, QEMU_THREAD_JOINABLE); + edu, QEMU_THREAD_JOINABLE, &error_abort); =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..5bc2cf4540 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -538,8 +538,10 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *c= pu, pending->shift =3D shift; pending->ret =3D H_HARDWARE; =20 + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&pending->thread, "sPAPR HPT prepare", - hpt_prepare_thread, pending, QEMU_THREAD_DETACHED); + hpt_prepare_thread, pending, + QEMU_THREAD_DETACHED, &error_abort); =20 spapr->pending_hpt =3D pending; =20 diff --git a/hw/rdma/rdma_backend.c b/hw/rdma/rdma_backend.c index c28bfbd44d..25e0c7d0f5 100644 --- a/hw/rdma/rdma_backend.c +++ b/hw/rdma/rdma_backend.c @@ -263,7 +263,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)(void *ctx, diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index 25976ed84f..f8ff7ff4a3 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -544,10 +544,11 @@ static void emulated_realize(CCIDCardState *base, Err= or **errp) error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_C= CID); goto out2; } + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, - card, QEMU_THREAD_JOINABLE); + card, QEMU_THREAD_JOINABLE, &error_abort); qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thr= ead, - card, QEMU_THREAD_JOINABLE); + card, QEMU_THREAD_JOINABLE, &error_abort); =20 out2: clean_event_notifier(card); diff --git a/include/qemu/thread.h b/include/qemu/thread.h index 55d83a907c..12291f4ccd 100644 --- a/include/qemu/thread.h +++ b/include/qemu/thread.h @@ -152,9 +152,9 @@ void qemu_event_reset(QemuEvent *ev); void qemu_event_wait(QemuEvent *ev); void qemu_event_destroy(QemuEvent *ev); =20 -void qemu_thread_create(QemuThread *thread, const char *name, +bool 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/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 2fb1cdf55d..8e8aa01999 100644 --- a/iothread.c +++ b/iothread.c @@ -178,8 +178,9 @@ static void iothread_complete(UserCreatable *obj, Error= **errp) */ name =3D object_get_canonical_path_component(OBJECT(obj)); thread_name =3D g_strdup_printf("IO %s", name); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&iothread->thread, thread_name, iothread_run, - iothread, QEMU_THREAD_JOINABLE); + iothread, QEMU_THREAD_JOINABLE, &error_abort); g_free(thread_name); g_free(name); =20 diff --git a/migration/migration.c b/migration/migration.c index ded151b1bf..ea5839ff0d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -447,8 +447,10 @@ static void process_incoming_migration_co(void *opaque) goto fail; } =20 + /* TODO: let the further caller handle the error instead of abort(= ) */ 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, &error_abort); mis->have_colo_incoming_thread =3D true; qemu_coroutine_yield(); =20 @@ -2358,8 +2360,10 @@ static int open_return_path_on_source(MigrationState= *ms, return 0; } =20 + /* TODO: let the further caller handle the error instead of abort() he= re */ 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, &error_abort); =20 trace_open_return_path_on_source_continue(); =20 @@ -3189,8 +3193,9 @@ void migrate_fd_connect(MigrationState *s, Error *err= or_in) migrate_fd_cleanup(s); return; } + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&s->thread, "live_migration", migration_thread, s, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); s->migration_thread_running =3D true; } =20 diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index fa09dba534..221ea24919 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1109,8 +1109,10 @@ int postcopy_ram_enable_notify(MigrationIncomingStat= e *mis) } =20 qemu_sem_init(&mis->fault_thread_sem, 0); + /* TODO: let the further caller handle the error instead of abort() he= re */ 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, &error_abort); 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 435a8d2946..eed1daf302 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -502,9 +502,10 @@ static int compress_threads_save_setup(void) comp_param[i].quit =3D false; qemu_mutex_init(&comp_param[i].mutex); qemu_cond_init(&comp_param[i].cond); + /* TODO: let the further caller handle the error instead of abort(= ) */ qemu_thread_create(compress_threads + i, "compress", do_data_compress, comp_param + i, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); } return 0; =20 @@ -1075,8 +1076,9 @@ static void multifd_new_send_channel_async(QIOTask *t= ask, gpointer opaque) p->c =3D QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); p->running =3D true; + /* TODO: let the further caller handle the error instead of abort(= ) */ qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); =20 atomic_inc(&multifd_send_state->count); } @@ -1355,8 +1357,9 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) p->num_packets =3D 1; =20 p->running =3D true; + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); atomic_inc(&multifd_recv_state->count); return atomic_read(&multifd_recv_state->count) =3D=3D migrate_multifd_channels(); @@ -3643,9 +3646,10 @@ static int compress_threads_load_setup(QEMUFile *f) qemu_cond_init(&decomp_param[i].cond); decomp_param[i].done =3D true; decomp_param[i].quit =3D false; + /* TODO: let the further caller handle the error instead of abort(= ) */ qemu_thread_create(decompress_threads + i, "decompress", do_data_decompress, decomp_param + i, - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); } return 0; exit: diff --git a/migration/savevm.c b/migration/savevm.c index d784e8aa40..46ce7af239 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1747,9 +1747,10 @@ static int loadvm_postcopy_handle_listen(MigrationIn= comingState *mis) mis->have_listen_thread =3D true; /* Start up the listening thread and wait for it to signal ready */ qemu_sem_init(&mis->listen_thread_sem, 0); + /* TODO: let the further caller handle the error instead of abort() he= re */ qemu_thread_create(&mis->listen_thread, "postcopy/listen", postcopy_ram_listen_thread, NULL, - QEMU_THREAD_DETACHED); + QEMU_THREAD_DETACHED, &error_abort); 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 ab4e708180..85e1af2f84 100644 --- a/tests/qht-bench.c +++ b/tests/qht-bench.c @@ -10,6 +10,7 @@ #include "qemu/qht.h" #include "qemu/rcu.h" #include "qemu/xxhash.h" +#include "qapi/error.h" =20 struct thread_stats { size_t rd; @@ -248,7 +249,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 2e6f70bd59..0f7da81291 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 929391f85d..5712f1f501 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 /* @@ -339,7 +340,8 @@ void vnc_start_worker_thread(void) return ; =20 q =3D vnc_queue_init(); - qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, q, - QEMU_THREAD_DETACHED); + /* TODO: let the further caller handle the error instead of abort() he= re */ + qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, + q, QEMU_THREAD_DETACHED, &error_abort); queue =3D q; /* Set global queue */ } diff --git a/util/compatfd.c b/util/compatfd.c index 980bd33e52..c3d8448264 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 @@ -88,8 +89,9 @@ static int qemu_signalfd_compat(const sigset_t *mask) memcpy(&info->mask, mask, sizeof(*mask)); info->fd =3D fds[1]; =20 - qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, info, - QEMU_THREAD_DETACHED); + /* TODO: let the further caller handle the error instead of abort() he= re */ + qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, + info, QEMU_THREAD_DETACHED, &error_abort); =20 return fds[0]; } diff --git a/util/oslib-posix.c b/util/oslib-posix.c index c1bee2a581..251e2f1aea 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -448,9 +448,10 @@ static bool touch_all_pages(char *area, size_t hpagesi= ze, size_t numpages, memset_thread[i].numpages =3D (i =3D=3D (memset_num_threads - 1)) ? numpages : numpages_per_thread; memset_thread[i].hpagesize =3D hpagesize; + /* TODO: let the callers handle the error instead of abort() here = */ qemu_thread_create(&memset_thread[i].pgthread, "touch_pages", do_touch_pages, &memset_thread[i], - QEMU_THREAD_JOINABLE); + QEMU_THREAD_JOINABLE, &error_abort); addr +=3D size_per_thread; numpages -=3D numpages_per_thread; } diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 865e476df5..39834b0551 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 @@ -500,9 +501,13 @@ static void *qemu_thread_start(void *args) return r; } =20 -void qemu_thread_create(QemuThread *thread, const char *name, - void *(*start_routine)(void*), - void *arg, int mode) +/* + * Return a boolean: true/false to indicate whether it succeeds. + * If fails, propagate the error to Error **errp and set the errno. + */ +bool qemu_thread_create(QemuThread *thread, const char *name, + void *(*start_routine)(void *), + void *arg, int mode, Error **errp) { sigset_t set, oldset; int err; @@ -511,7 +516,9 @@ void qemu_thread_create(QemuThread *thread, const char = *name, =20 err =3D pthread_attr_init(&attr); if (err) { - error_exit(err, __func__); + errno =3D err; + error_setg_errno(errp, errno, "pthread_attr_init failed"); + return false; } =20 if (mode =3D=3D QEMU_THREAD_DETACHED) { @@ -529,13 +536,19 @@ void qemu_thread_create(QemuThread *thread, const cha= r *name, =20 err =3D pthread_create(&thread->thread, &attr, qemu_thread_start, qemu_thread_args); - - if (err) - error_exit(err, __func__); + if (err) { + errno =3D err; + error_setg_errno(errp, errno, "pthread_create failed"); + pthread_attr_destroy(&attr); + g_free(qemu_thread_args->name); + g_free(qemu_thread_args); + return false; + } =20 pthread_sigmask(SIG_SETMASK, &oldset, NULL); =20 pthread_attr_destroy(&attr); + return true; } =20 void qemu_thread_get_self(QemuThread *thread) diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 4a363ca675..57b1143e97 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; @@ -388,9 +389,9 @@ void *qemu_thread_join(QemuThread *thread) return ret; } =20 -void qemu_thread_create(QemuThread *thread, const char *name, - void *(*start_routine)(void *), - void *arg, int mode) +bool qemu_thread_create(QemuThread *thread, const char *name, + void *(*start_routine)(void *), + void *arg, int mode, Error **errp) { HANDLE hThread; struct QemuThreadData *data; @@ -409,10 +410,17 @@ void qemu_thread_create(QemuThread *thread, const cha= r *name, hThread =3D (HANDLE) _beginthreadex(NULL, 0, win32_start_routine, data, 0, &thread->tid); if (!hThread) { - error_exit(GetLastError(), __func__); + if (data->mode !=3D QEMU_THREAD_DETACHED) { + DeleteCriticalSection(&data->cs); + } + error_setg_errno(errp, errno, + "failed to create win32_start_routine"); + g_free(data); + return false; } CloseHandle(hThread); thread->data =3D data; + return true; } =20 void qemu_thread_get_self(QemuThread *thread) 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 From nobody Sat Apr 27 15:54:21 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; 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 1545747351270366.04736844041554; Tue, 25 Dec 2018 06:15:51 -0800 (PST) Received: from localhost ([127.0.0.1]:41575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnUr-0004P1-Mt for importer@patchew.org; Tue, 25 Dec 2018 09:15:49 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKv-0001Nw-5z for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKt-0003p3-4m for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:33 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:51031) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKs-0003oE-Na for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:31 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:27 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:40 +0800 Message-Id: <20181225140449.15786-8-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 07/16] qemu_thread: supplement error handling for qemu_X_start_vcpu 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: lifei1214@126.com, Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The callers of qemu_init_vcpu() already passed the **errp to handle errors. In view of this, add a new Error parameter to qemu_init_vcpu() and all qemu_X_start_vcpu() functions called by qemu_init_vcpu() to propagate the error and let the further callers check it. Besides, make qemu_init_vcpu() return a Boolean value to let its callers know whether it succeeds. Cc: Paolo Bonzini Signed-off-by: Fei Li Reviewed-by: Fam Zheng Reviewed-by: Juan Quintela --- accel/tcg/user-exec-stub.c | 3 +- cpus.c | 86 ++++++++++++++++++++++++-------------= ---- include/qom/cpu.h | 2 +- target/alpha/cpu.c | 4 +- target/arm/cpu.c | 4 +- target/cris/cpu.c | 4 +- target/hppa/cpu.c | 4 +- target/i386/cpu.c | 4 +- target/lm32/cpu.c | 4 +- target/m68k/cpu.c | 4 +- target/microblaze/cpu.c | 4 +- target/mips/cpu.c | 4 +- target/moxie/cpu.c | 4 +- target/nios2/cpu.c | 4 +- target/openrisc/cpu.c | 4 +- target/ppc/translate_init.inc.c | 4 +- target/riscv/cpu.c | 4 +- target/s390x/cpu.c | 4 +- target/sh4/cpu.c | 4 +- target/sparc/cpu.c | 4 +- target/tilegx/cpu.c | 4 +- target/tricore/cpu.c | 4 +- target/unicore32/cpu.c | 4 +- target/xtensa/cpu.c | 4 +- 24 files changed, 117 insertions(+), 58 deletions(-) diff --git a/accel/tcg/user-exec-stub.c b/accel/tcg/user-exec-stub.c index a32b4496af..f8c38a375c 100644 --- a/accel/tcg/user-exec-stub.c +++ b/accel/tcg/user-exec-stub.c @@ -10,8 +10,9 @@ void cpu_resume(CPUState *cpu) { } =20 -void qemu_init_vcpu(CPUState *cpu) +bool qemu_init_vcpu(CPUState *cpu, Error **errp) { + return true; } =20 /* User mode emulation does not support record/replay yet. */ diff --git a/cpus.c b/cpus.c index 25df03326b..e8450e518a 100644 --- a/cpus.c +++ b/cpus.c @@ -1931,7 +1931,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; @@ -1961,17 +1961,20 @@ static void qemu_tcg_init_vcpu(CPUState *cpu) snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", cpu->cpu_index); =20 - /* TODO: let the callers handle the error instead of abort() h= ere */ - qemu_thread_create(cpu->thread, thread_name, qemu_tcg_cpu_thre= ad_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, + qemu_tcg_cpu_thread_fn, cpu, + QEMU_THREAD_JOINABLE, errp)) { + return; + } =20 } else { /* share a single thread for all cpus with TCG */ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); - /* TODO: let the callers handle the error instead of abort() h= ere */ - qemu_thread_create(cpu->thread, thread_name, - qemu_tcg_rr_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, + qemu_tcg_rr_cpu_thread_fn, cpu, + QEMU_THREAD_JOINABLE, errp)) { + return; + } =20 single_tcg_halt_cond =3D cpu->halt_cond; single_tcg_cpu_thread =3D cpu->thread; @@ -1989,7 +1992,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 @@ -1999,15 +2002,16 @@ static void qemu_hax_start_vcpu(CPUState *cpu) =20 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HAX", cpu->cpu_index); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(cpu->thread, thread_name, qemu_hax_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, qemu_hax_cpu_thread_= fn, + cpu, QEMU_THREAD_JOINABLE, errp)) { + return; + } #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #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 @@ -2016,12 +2020,13 @@ static void qemu_kvm_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/KVM", cpu->cpu_index); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(cpu->thread, thread_name, qemu_kvm_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, qemu_kvm_cpu_thread_= fn, + cpu, QEMU_THREAD_JOINABLE, errp)) { + /* keep 'if' here in case there is further error handling logic */ + } } =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 @@ -2035,12 +2040,13 @@ static void qemu_hvf_start_vcpu(CPUState *cpu) =20 snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/HVF", cpu->cpu_index); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, qemu_hvf_cpu_thread_= fn, + cpu, QEMU_THREAD_JOINABLE, errp)) { + /* keep 'if' here in case there is further error handling logic */ + } } =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 @@ -2049,15 +2055,16 @@ static void qemu_whpx_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/WHPX", cpu->cpu_index); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, qemu_whpx_cpu_thread= _fn, + cpu, QEMU_THREAD_JOINABLE, errp)) { + return; + } #ifdef _WIN32 cpu->hThread =3D qemu_thread_get_handle(cpu->thread); #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 @@ -2066,16 +2073,18 @@ static void qemu_dummy_start_vcpu(CPUState *cpu) qemu_cond_init(cpu->halt_cond); snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/DUMMY", cpu->cpu_index); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(cpu->thread, thread_name, qemu_dummy_cpu_thread_fn, - cpu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(cpu->thread, thread_name, qemu_dummy_cpu_threa= d_fn, + cpu, QEMU_THREAD_JOINABLE, errp)) { + /* keep 'if' here in case there is further error handling logic */ + } } =20 -void qemu_init_vcpu(CPUState *cpu) +bool 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, @@ -2086,22 +2095,29 @@ 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 false; } =20 while (!cpu->created) { qemu_cond_wait(&qemu_cpu_cond, &qemu_global_mutex); } + + return true; } =20 void cpu_stop_current(void) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 1396f53e5b..696c3608d2 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -1006,7 +1006,7 @@ void end_exclusive(void); * * Initializes a vCPU. */ -void qemu_init_vcpu(CPUState *cpu); +bool 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 a953897fcc..bf3c34516d 100644 --- a/target/alpha/cpu.c +++ b/target/alpha/cpu.c @@ -66,7 +66,9 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 acc->parent_realize(dev, errp); } diff --git a/target/arm/cpu.c b/target/arm/cpu.c index c8505eaaee..ef745ff4c7 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1125,7 +1125,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) } #endif =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } cpu_reset(cs); =20 acc->parent_realize(dev, errp); diff --git a/target/cris/cpu.c b/target/cris/cpu.c index a23aba2688..ec92d69781 100644 --- a/target/cris/cpu.c +++ b/target/cris/cpu.c @@ -140,7 +140,9 @@ static void cris_cpu_realizefn(DeviceState *dev, Error = **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 ccc->parent_realize(dev, errp); } diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c index 00bf444620..08f600ced9 100644 --- a/target/hppa/cpu.c +++ b/target/hppa/cpu.c @@ -98,7 +98,9 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **= errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } acc->parent_realize(dev, errp); =20 #ifndef CONFIG_USER_ONLY diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 677a3bd5fb..21fc8122eb 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5279,7 +5279,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) } #endif =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + 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..d50b1e4a43 100644 --- a/target/lm32/cpu.c +++ b/target/lm32/cpu.c @@ -139,7 +139,9 @@ static void lm32_cpu_realizefn(DeviceState *dev, Error = **errp) =20 cpu_reset(cs); =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 lcc->parent_realize(dev, errp); } diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c index 582e3a73b3..4ab53f2d58 100644 --- a/target/m68k/cpu.c +++ b/target/m68k/cpu.c @@ -231,7 +231,9 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error = **errp) m68k_cpu_init_gdb(cpu); =20 cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 mcc->parent_realize(dev, errp); } diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c index 9b546a2c18..3906c864a3 100644 --- a/target/microblaze/cpu.c +++ b/target/microblaze/cpu.c @@ -161,7 +161,9 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **= errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + 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 e217fb3e36..1e5aa69c57 100644 --- a/target/mips/cpu.c +++ b/target/mips/cpu.c @@ -145,7 +145,9 @@ static void mips_cpu_realizefn(DeviceState *dev, Error = **errp) cpu_mips_realize_env(&cpu->env); =20 cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 mcc->parent_realize(dev, errp); } diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c index 8d67eb6727..8581a6d922 100644 --- a/target/moxie/cpu.c +++ b/target/moxie/cpu.c @@ -66,7 +66,9 @@ static void moxie_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } cpu_reset(cs); =20 mcc->parent_realize(dev, errp); diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c index fbfaa2ce26..5c7b4b486e 100644 --- a/target/nios2/cpu.c +++ b/target/nios2/cpu.c @@ -94,7 +94,9 @@ static void nios2_cpu_realizefn(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } cpu_reset(cs); =20 ncc->parent_realize(dev, errp); diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index fb7cb5c507..a6dcdb9df9 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -83,7 +83,9 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Erro= r **errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + 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 03f1d34a97..2fba2e4741 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -9711,7 +9711,9 @@ static void ppc_cpu_realize(DeviceState *dev, Error *= *errp) 32, "power-vsx.xml", 0); } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + goto unrealize; + } =20 pcc->parent_realize(dev, errp); =20 diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index a025a0a3ba..9829fd9bc4 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -305,7 +305,9 @@ static void riscv_cpu_realize(DeviceState *dev, Error *= *errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } cpu_reset(cs); =20 mcc->parent_realize(dev, errp); diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 18ba7f85a5..2a3eac9761 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -222,7 +222,9 @@ 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); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =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..d32ef2e1cb 100644 --- a/target/sh4/cpu.c +++ b/target/sh4/cpu.c @@ -196,7 +196,9 @@ static void superh_cpu_realizefn(DeviceState *dev, Erro= r **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 scc->parent_realize(dev, errp); } diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index 0f090ece54..9c22f6a7df 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -773,7 +773,9 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error= **errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 scc->parent_realize(dev, errp); } diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c index bfe9be59b5..234148fabd 100644 --- a/target/tilegx/cpu.c +++ b/target/tilegx/cpu.c @@ -92,7 +92,9 @@ static void tilegx_cpu_realizefn(DeviceState *dev, Error = **errp) } =20 cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 tcc->parent_realize(dev, errp); } diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index 2edaef1aef..5482d6ea3f 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -96,7 +96,9 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error= **errp) set_feature(env, TRICORE_FEATURE_13); } cpu_reset(cs); - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 tcc->parent_realize(dev, errp); } diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c index 2b49d1ca40..0c737c3187 100644 --- a/target/unicore32/cpu.c +++ b/target/unicore32/cpu.c @@ -96,7 +96,9 @@ static void uc32_cpu_realizefn(DeviceState *dev, Error **= errp) return; } =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 ucc->parent_realize(dev, errp); } diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index a54dbe4260..d2351c9b20 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -131,7 +131,9 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Erro= r **errp) =20 cs->gdb_num_regs =3D xcc->config->gdb_regmap.num_regs; =20 - qemu_init_vcpu(cs); + if (!qemu_init_vcpu(cs, errp)) { + return; + } =20 xcc->parent_realize(dev, errp); } --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 154574704036061.77202986678458; Tue, 25 Dec 2018 06:10:40 -0800 (PST) Received: from localhost ([127.0.0.1]:41513 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnPr-0006Mr-1d for importer@patchew.org; Tue, 25 Dec 2018 09:10:39 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKw-0001OV-L4 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKv-0003qb-GA for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:34 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:60285) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKv-0003pj-6Z for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:33 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:29 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:41 +0800 Message-Id: <20181225140449.15786-9-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 08/16] qemu_thread: supplement error handling for qmp_dump_guest_memory 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: lifei1214@126.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Utilize the existed errp to propagate the error instead of the temporary &error_abort. Cc: Markus Armbruster Cc: Marc-Andr=C3=A9 Lureau Signed-off-by: Fei Li --- dump.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dump.c b/dump.c index c35d6ddd22..ef5ea324fa 100644 --- a/dump.c +++ b/dump.c @@ -2020,9 +2020,10 @@ void qmp_dump_guest_memory(bool paging, const char *= file, if (detach_p) { /* detached dump */ s->detached =3D true; - /* TODO: let the further caller handle the error instead of abort(= ) */ - qemu_thread_create(&s->dump_thread, "dump_thread", dump_thread, - s, QEMU_THREAD_DETACHED, &error_abort); + if (!qemu_thread_create(&s->dump_thread, "dump_thread", dump_threa= d, + s, QEMU_THREAD_DETACHED, errp)) { + /* keep 'if' here in case there is further error handling logi= c */ + } } else { /* sync dump */ dump_process(s, errp); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 154574686930066.26856921524734; Tue, 25 Dec 2018 06:07:49 -0800 (PST) Received: from localhost ([127.0.0.1]:41492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnN5-0003Be-Sb for importer@patchew.org; Tue, 25 Dec 2018 09:07:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnKy-0001R0-Oi for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnKy-0003s5-0x for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:36 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:54949) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnKx-0003rQ-NK for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:35 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:32 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:42 +0800 Message-Id: <20181225140449.15786-10-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 09/16] qemu_thread: supplement error handling for pci_edu_realize 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: lifei1214@126.com, Jiri Slaby , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Utilize the existed errp to propagate the error instead of the temporary &error_abort. Cc: Markus Armbruster Cc: Jiri Slaby Signed-off-by: Fei Li --- hw/misc/edu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/misc/edu.c b/hw/misc/edu.c index 3f4ba7ded3..011fe6e0b7 100644 --- a/hw/misc/edu.c +++ b/hw/misc/edu.c @@ -356,9 +356,10 @@ static void pci_edu_realize(PCIDevice *pdev, Error **e= rrp) =20 qemu_mutex_init(&edu->thr_mutex); qemu_cond_init(&edu->thr_cond); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&edu->thread, "edu", edu_fact_thread, - edu, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&edu->thread, "edu", edu_fact_thread, + edu, QEMU_THREAD_JOINABLE, errp)) { + return; + } =20 memory_region_init_io(&edu->mmio, OBJECT(edu), &edu_mmio_ops, edu, "edu-mmio", 1 * MiB); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 15457472149141003.2585577447088; Tue, 25 Dec 2018 06:13:34 -0800 (PST) Received: from localhost ([127.0.0.1]:41545 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnSf-0001cM-E8 for importer@patchew.org; Tue, 25 Dec 2018 09:13:33 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnL3-0001Vs-MU for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnL0-0003tA-Fw for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:41 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:37466) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnL0-0003sl-6K for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:38 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:34 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:43 +0800 Message-Id: <20181225140449.15786-11-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 10/16] qemu_thread: supplement error handling for h_resize_hpt_prepare 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: lifei1214@126.com, Markus Armbruster , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a local_err to hold the error, and return the corresponding error code to replace the temporary &error_abort. Cc: Markus Armbruster Cc: David Gibson Signed-off-by: Fei Li Acked-by: David Gibson --- hw/ppc/spapr_hcall.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 5bc2cf4540..7c16ade04a 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; @@ -538,10 +539,13 @@ static target_ulong h_resize_hpt_prepare(PowerPCCPU *= cpu, pending->shift =3D shift; pending->ret =3D H_HARDWARE; =20 - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&pending->thread, "sPAPR HPT prepare", - hpt_prepare_thread, pending, - QEMU_THREAD_DETACHED, &error_abort); + if (!qemu_thread_create(&pending->thread, "sPAPR HPT prepare", + hpt_prepare_thread, pending, + QEMU_THREAD_DETACHED, &local_err)) { + error_reportf_err(local_err, "failed to create hpt_prepare_thread:= "); + g_free(pending); + return H_RESOURCE; + } =20 spapr->pending_hpt =3D pending; =20 --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747209239644.8192017700152; Tue, 25 Dec 2018 06:13:29 -0800 (PST) Received: from localhost ([127.0.0.1]:41541 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnSZ-0001Tt-4u for importer@patchew.org; Tue, 25 Dec 2018 09:13:27 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33246) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnL3-0001Vr-MI for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnL2-0003u7-TV for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:41 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:54768) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnL2-0003ti-KE for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:40 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:37 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:44 +0800 Message-Id: <20181225140449.15786-12-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 11/16] qemu_thread: supplement error handling for emulated_realize 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: lifei1214@126.com, "Cc : Markus Armbruster" , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Utilize the existed errp to propagate the error and do the corresponding cleanup to replace the temporary &error_abort. Cc: Cc: Markus Armbruster Cc: Gerd Hoffmann Signed-off-by: Fei Li --- hw/usb/ccid-card-emulated.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hw/usb/ccid-card-emulated.c b/hw/usb/ccid-card-emulated.c index f8ff7ff4a3..9245b4fcad 100644 --- a/hw/usb/ccid-card-emulated.c +++ b/hw/usb/ccid-card-emulated.c @@ -32,7 +32,6 @@ #include "qemu/thread.h" #include "qemu/main-loop.h" #include "ccid.h" -#include "qapi/error.h" =20 #define DPRINTF(card, lvl, fmt, ...) \ do {\ @@ -544,11 +543,15 @@ static void emulated_realize(CCIDCardState *base, Err= or **errp) error_setg(errp, "%s: failed to initialize vcard", TYPE_EMULATED_C= CID); goto out2; } - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&card->event_thread_id, "ccid/event", event_thread, - card, QEMU_THREAD_JOINABLE, &error_abort); - qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", handle_apdu_thr= ead, - card, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&card->event_thread_id, "ccid/event", event_th= read, + card, QEMU_THREAD_JOINABLE, errp)) { + goto out2; + } + if (!qemu_thread_create(&card->apdu_thread_id, "ccid/apdu", + handle_apdu_thread, card, + QEMU_THREAD_JOINABLE, errp)) { + goto out2; + } =20 out2: clean_event_notifier(card); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747352629993.162945398127; Tue, 25 Dec 2018 06:15:52 -0800 (PST) Received: from localhost ([127.0.0.1]:41577 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnUt-0004RD-A7 for importer@patchew.org; Tue, 25 Dec 2018 09:15:51 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnL6-0001Yy-5m for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnL5-0003vI-Db for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:44 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:51882) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnL5-0003un-46 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:43 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:39 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:45 +0800 Message-Id: <20181225140449.15786-13-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 12/16] qemu_thread: supplement error handling for iothread_complete/qemu_signalfd_compat 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: lifei1214@126.com, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For iothread_complete: utilize the existed errp to propagate the error and do the corresponding cleanup to replace the temporary &error_abort. For qemu_signalfd_compat: add a local_err to hold the error, and return the corresponding error code to replace the temporary &error_abort. Cc: Markus Armbruster Cc: Eric Blake Signed-off-by: Fei Li --- iothread.c | 17 +++++++++++------ util/compatfd.c | 11 ++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/iothread.c b/iothread.c index 8e8aa01999..7335dacf0b 100644 --- a/iothread.c +++ b/iothread.c @@ -164,9 +164,7 @@ static void iothread_complete(UserCreatable *obj, Error= **errp) &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); @@ -178,9 +176,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); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&iothread->thread, thread_name, iothread_run, - iothread, QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&iothread->thread, thread_name, iothread_run, + iothread, QEMU_THREAD_JOINABLE, errp)) { + g_free(thread_name); + g_free(name); + goto fail; + } g_free(thread_name); g_free(name); =20 @@ -191,6 +192,10 @@ static void iothread_complete(UserCreatable *obj, Erro= r **errp) &iothread->init_done_lock); } qemu_mutex_unlock(&iothread->init_done_lock); + return; +fail: + aio_context_unref(iothread->ctx); + iothread->ctx =3D NULL; } =20 typedef struct { diff --git a/util/compatfd.c b/util/compatfd.c index c3d8448264..9cb13381e4 100644 --- a/util/compatfd.c +++ b/util/compatfd.c @@ -71,6 +71,7 @@ static int qemu_signalfd_compat(const sigset_t *mask) 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) { @@ -89,9 +90,13 @@ static int qemu_signalfd_compat(const sigset_t *mask) memcpy(&info->mask, mask, sizeof(*mask)); info->fd =3D fds[1]; =20 - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, - info, QEMU_THREAD_DETACHED, &error_abort); + if (!qemu_thread_create(&thread, "signalfd_compat", sigwait_compat, + info, QEMU_THREAD_DETACHED, &local_err)) { + close(fds[0]); + close(fds[1]); + free(info); + return -1; + } =20 return fds[0]; } --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747474253341.23284916432624; Tue, 25 Dec 2018 06:17:54 -0800 (PST) Received: from localhost ([127.0.0.1]:41590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnWq-0006QZ-PL for importer@patchew.org; Tue, 25 Dec 2018 09:17:52 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnLL-0001qm-Gy for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnLI-0003zp-8I for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:59 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:58376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnLH-0003vx-RC for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:56 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:42 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:46 +0800 Message-Id: <20181225140449.15786-14-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 13/16] qemu_thread: supplement error handling for migration 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: lifei1214@126.com, Markus Armbruster , Peter Xu , "Dr . David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Update qemu_thread_create()'s callers by - setting an error on qemu_thread_create() failure for callers that set an error on failure; - reporting the error and returning failure for callers that return an error code on failure; - reporting the error and setting some state for callers that just report errors and choose not to continue on. Cc: Markus Armbruster Cc: Dr. David Alan Gilbert Cc: Peter Xu Signed-off-by: Fei Li Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 33 ++++++++++++++++++++++----------- migration/postcopy-ram.c | 16 ++++++++++++---- migration/ram.c | 44 ++++++++++++++++++++++++++++++-------------- migration/savevm.c | 12 ++++++++---- 4 files changed, 72 insertions(+), 33 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index ea5839ff0d..9654bde101 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -447,10 +447,13 @@ static void process_incoming_migration_co(void *opaqu= e) goto fail; } =20 - /* TODO: let the further caller handle the error instead of abort(= ) */ - qemu_thread_create(&mis->colo_incoming_thread, "COLO incoming", - colo_process_incoming_thread, mis, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&mis->colo_incoming_thread, "COLO incoming= ", + colo_process_incoming_thread, mis, + QEMU_THREAD_JOINABLE, &local_err)) { + error_reportf_err(local_err, "failed to create " + "colo_process_incoming_thread: "); + goto fail; + } mis->have_colo_incoming_thread =3D true; qemu_coroutine_yield(); =20 @@ -2347,6 +2350,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) { @@ -2360,10 +2364,13 @@ static int open_return_path_on_source(MigrationStat= e *ms, return 0; } =20 - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&ms->rp_state.rp_thread, "return path", - source_return_path_thread, ms, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&ms->rp_state.rp_thread, "return path", + source_return_path_thread, ms, + QEMU_THREAD_JOINABLE, &local_err)) { + error_reportf_err(local_err, + "failed to create source_return_path_thread: "); + return -1; + } =20 trace_open_return_path_on_source_continue(); =20 @@ -3193,9 +3200,13 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) migrate_fd_cleanup(s); return; } - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&s->thread, "live_migration", migration_thread, s, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&s->thread, "live_migration", migration_thread= , s, + QEMU_THREAD_JOINABLE, &error_in)) { + error_reportf_err(error_in, "failed to create migration_thread: "); + 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 221ea24919..80bfa9c4a2 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1083,6 +1083,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,10 +1111,16 @@ int postcopy_ram_enable_notify(MigrationIncomingSta= te *mis) } =20 qemu_sem_init(&mis->fault_thread_sem, 0); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&mis->fault_thread, "postcopy/fault", - postcopy_ram_fault_thread, mis, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&mis->fault_thread, "postcopy/fault", + postcopy_ram_fault_thread, mis, + QEMU_THREAD_JOINABLE, &local_err)) { + error_reportf_err(local_err, + "failed to create postcopy_ram_fault_thread: "); + close(mis->userfault_event_fd); + close(mis->userfault_fd); + 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 eed1daf302..1e24a78eaa 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -473,6 +473,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; @@ -502,10 +503,12 @@ static int compress_threads_save_setup(void) comp_param[i].quit =3D false; qemu_mutex_init(&comp_param[i].mutex); qemu_cond_init(&comp_param[i].cond); - /* TODO: let the further caller handle the error instead of abort(= ) */ - qemu_thread_create(compress_threads + i, "compress", - do_data_compress, comp_param + i, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(compress_threads + i, "compress", + do_data_compress, comp_param + i, + QEMU_THREAD_JOINABLE, &local_err)) { + error_reportf_err(local_err, "failed to create do_data_compres= s: "); + goto exit; + } } return 0; =20 @@ -1076,9 +1079,14 @@ static void multifd_new_send_channel_async(QIOTask *= task, gpointer opaque) p->c =3D QIO_CHANNEL(sioc); qio_channel_set_delay(p->c, false); p->running =3D true; - /* TODO: let the further caller handle the error instead of abort(= ) */ - qemu_thread_create(&p->thread, p->name, multifd_send_thread, p, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&p->thread, p->name, multifd_send_thread, = p, + QEMU_THREAD_JOINABLE, &local_err)) { + migrate_set_error(migrate_get_current(), local_err); + error_reportf_err(local_err, + "failed to create multifd_send_thread: "); + multifd_save_cleanup(); + return; + } =20 atomic_inc(&multifd_send_state->count); } @@ -1357,9 +1365,13 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error= **errp) p->num_packets =3D 1; =20 p->running =3D true; - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, + QEMU_THREAD_JOINABLE, &local_err)) { + error_propagate_prepend(errp, local_err, + "failed to create multifd_recv_thread: "); + multifd_recv_terminate_threads(local_err); + return false; + } atomic_inc(&multifd_recv_state->count); return atomic_read(&multifd_recv_state->count) =3D=3D migrate_multifd_channels(); @@ -3625,6 +3637,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; @@ -3646,10 +3659,13 @@ static int compress_threads_load_setup(QEMUFile *f) qemu_cond_init(&decomp_param[i].cond); decomp_param[i].done =3D true; decomp_param[i].quit =3D false; - /* TODO: let the further caller handle the error instead of abort(= ) */ - qemu_thread_create(decompress_threads + i, "decompress", - do_data_decompress, decomp_param + i, - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(decompress_threads + i, "decompress", + do_data_decompress, decomp_param + i, + QEMU_THREAD_JOINABLE, &local_err)) { + error_reportf_err(local_err, + "failed to create do_data_decompress: "); + goto exit; + } } return 0; exit: diff --git a/migration/savevm.c b/migration/savevm.c index 46ce7af239..b8bdcde5d8 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1747,10 +1747,14 @@ static int loadvm_postcopy_handle_listen(MigrationI= ncomingState *mis) mis->have_listen_thread =3D true; /* Start up the listening thread and wait for it to signal ready */ qemu_sem_init(&mis->listen_thread_sem, 0); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&mis->listen_thread, "postcopy/listen", - postcopy_ram_listen_thread, NULL, - QEMU_THREAD_DETACHED, &error_abort); + if (!qemu_thread_create(&mis->listen_thread, "postcopy/listen", + postcopy_ram_listen_thread, NULL, + QEMU_THREAD_DETACHED, &local_err)) { + error_reportf_err(local_err, + "failed to create postcopy_ram_listen_thread: "); + qemu_sem_destroy(&mis->listen_thread_sem); + return -1; + } qemu_sem_wait(&mis->listen_thread_sem); qemu_sem_destroy(&mis->listen_thread_sem); =20 --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 154574704991371.02946231371311; Tue, 25 Dec 2018 06:10:49 -0800 (PST) Received: from localhost ([127.0.0.1]:41521 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnQ0-0006f7-FJ for importer@patchew.org; Tue, 25 Dec 2018 09:10:48 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnLL-0001ql-GU for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnLK-00040t-L2 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:59 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:46221) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnLK-0003we-Bj for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:05:58 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:44 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:47 +0800 Message-Id: <20181225140449.15786-15-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 14/16] qemu_thread: supplement error handling for vnc_start_worker_thread 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: lifei1214@126.com, Markus Armbruster , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Supplement the error handling for vnc_thread_worker_thread: add an Error parameter for it to propagate the error to its caller to handle in case it fails, and make it return a Boolean to indicate whether it succeeds. Cc: Markus Armbruster Cc: Gerd Hoffmann Signed-off-by: Fei Li --- ui/vnc-jobs.c | 17 +++++++++++------ ui/vnc-jobs.h | 2 +- ui/vnc.c | 4 +++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index 5712f1f501..35a652d1fd 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -332,16 +332,21 @@ static bool vnc_worker_thread_running(void) return queue; /* Check global queue */ } =20 -void vnc_start_worker_thread(void) +bool vnc_start_worker_thread(Error **errp) { VncJobQueue *q; =20 - if (vnc_worker_thread_running()) - return ; + if (vnc_worker_thread_running()) { + goto out; + } =20 q =3D vnc_queue_init(); - /* TODO: let the further caller handle the error instead of abort() he= re */ - qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, - q, QEMU_THREAD_DETACHED, &error_abort); + if (!qemu_thread_create(&q->thread, "vnc_worker", vnc_worker_thread, + q, QEMU_THREAD_DETACHED, errp)) { + vnc_queue_clear(q); + return false; + } queue =3D q; /* Set global queue */ +out: + return true; } diff --git a/ui/vnc-jobs.h b/ui/vnc-jobs.h index 59f66bcc35..14640593db 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); +bool 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 0c1b477425..0ffe9e6a5d 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3236,7 +3236,9 @@ void vnc_display_init(const char *id, Error **errp) vd->connections_limit =3D 32; =20 qemu_mutex_init(&vd->mutex); - vnc_start_worker_thread(); + if (!vnc_start_worker_thread(errp)) { + return; + } =20 vd->dcl.ops =3D &dcl_ops; register_displaychangelistener(&vd->dcl); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747221482179.0666159951851; Tue, 25 Dec 2018 06:13:41 -0800 (PST) Received: from localhost ([127.0.0.1]:41547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnSl-0001jL-T4 for importer@patchew.org; Tue, 25 Dec 2018 09:13:39 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnLN-0001tk-Kb for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnLM-00041g-Px for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:01 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:46329) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnLM-0003xQ-GS for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:00 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:47 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:48 +0800 Message-Id: <20181225140449.15786-16-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 15/16] qemu_thread: supplement error handling for touch_all_pages 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: lifei1214@126.com, Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Supplement the error handling for touch_all_pages: add an Error parameter for it to propagate the error to its caller to do the handling in case it fails. Cc: Markus Armbruster Signed-off-by: Fei Li --- util/oslib-posix.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 251e2f1aea..afc1d99093 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -431,15 +431,17 @@ static inline int get_memset_num_threads(int smp_cpus) } =20 static bool touch_all_pages(char *area, size_t hpagesize, size_t numpages, - int smp_cpus) + int smp_cpus, Error **errp) { size_t numpages_per_thread; size_t size_per_thread; char *addr =3D area; int i =3D 0; + int started_thread =3D 0; =20 memset_thread_failed =3D false; memset_num_threads =3D get_memset_num_threads(smp_cpus); + started_thread =3D memset_num_threads; memset_thread =3D g_new0(MemsetThread, memset_num_threads); numpages_per_thread =3D (numpages / memset_num_threads); size_per_thread =3D (hpagesize * numpages_per_thread); @@ -448,14 +450,18 @@ static bool touch_all_pages(char *area, size_t hpages= ize, size_t numpages, memset_thread[i].numpages =3D (i =3D=3D (memset_num_threads - 1)) ? numpages : numpages_per_thread; memset_thread[i].hpagesize =3D hpagesize; - /* TODO: let the callers handle the error instead of abort() here = */ - qemu_thread_create(&memset_thread[i].pgthread, "touch_pages", - do_touch_pages, &memset_thread[i], - QEMU_THREAD_JOINABLE, &error_abort); + if (!qemu_thread_create(&memset_thread[i].pgthread, "touch_pages", + do_touch_pages, &memset_thread[i], + QEMU_THREAD_JOINABLE, errp)) { + memset_thread_failed =3D true; + started_thread =3D i; + goto out; + } addr +=3D size_per_thread; numpages -=3D numpages_per_thread; } - for (i =3D 0; i < memset_num_threads; i++) { +out: + for (i =3D 0; i < started_thread; i++) { qemu_thread_join(&memset_thread[i].pgthread); } g_free(memset_thread); @@ -471,6 +477,7 @@ void os_mem_prealloc(int fd, char *area, size_t memory,= int smp_cpus, struct sigaction act, oldact; size_t hpagesize =3D qemu_fd_getpagesize(fd); size_t numpages =3D DIV_ROUND_UP(memory, hpagesize); + Error *local_err =3D NULL; =20 memset(&act, 0, sizeof(act)); act.sa_handler =3D &sigbus_handler; @@ -484,9 +491,9 @@ void os_mem_prealloc(int fd, char *area, size_t memory,= int smp_cpus, } =20 /* touch pages simultaneously */ - if (touch_all_pages(area, hpagesize, numpages, smp_cpus)) { - error_setg(errp, "os_mem_prealloc: Insufficient free host memory " - "pages available to allocate guest RAM"); + if (touch_all_pages(area, hpagesize, numpages, smp_cpus, &local_err)) { + error_propagate_prepend(errp, local_err, "os_mem_prealloc: Insuffi= cient" + " free host memory pages available to allocate guest RAM: "); } =20 ret =3D sigaction(SIGBUS, &oldact, NULL); --=20 2.13.7 From nobody Sat Apr 27 15:54:21 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; 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 1545747604977765.2750001209796; Tue, 25 Dec 2018 06:20:04 -0800 (PST) Received: from localhost ([127.0.0.1]:41604 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnYx-000827-BF for importer@patchew.org; Tue, 25 Dec 2018 09:20:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:33346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gbnLP-0001x1-Pm for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gbnLP-00042Q-23 for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:03 -0500 Received: from smtp.nue.novell.com ([195.135.221.5]:36502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gbnLO-0003y2-Od for qemu-devel@nongnu.org; Tue, 25 Dec 2018 09:06:03 -0500 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 25 Dec 2018 15:05:49 +0100 From: Fei Li To: qemu-devel@nongnu.org, shirley17fei@gmail.com Date: Tue, 25 Dec 2018 22:04:49 +0800 Message-Id: <20181225140449.15786-17-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20181225140449.15786-1-fli@suse.com> References: <20181225140449.15786-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH for-4.0 v9 16/16] qemu_thread_join: fix segmentation fault 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: lifei1214@126.com, Stefan Weil Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To avoid the segmentation fault in qemu_thread_join(), just directly return when the QemuThread *thread failed to be created in either qemu-thread-posix.c or qemu-thread-win32.c. Cc: Stefan Weil Signed-off-by: Fei Li Reviewed-by: Fam Zheng Reviewed-by earlier. :) Thus to not make troube, I wrote the "remove..."=20 Reviewed-by patches be merged, including this v9 16/16 patch but not the=20 --- util/qemu-thread-posix.c | 3 +++ util/qemu-thread-win32.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 39834b0551..3548935dac 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -571,6 +571,9 @@ void *qemu_thread_join(QemuThread *thread) int err; void *ret; =20 + if (!thread->thread) { + return NULL; + } err =3D pthread_join(thread->thread, &ret); if (err) { error_exit(err, __func__); diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c index 57b1143e97..ca4d5329e3 100644 --- a/util/qemu-thread-win32.c +++ b/util/qemu-thread-win32.c @@ -367,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 --=20 2.13.7