From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>, Peter Xu <peterx@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Markus Armbruster <armbru@redhat.com>,
Juan Quintela <quintela@redhat.com>,
Thomas Huth <thuth@redhat.com>,
Li Zhijian <lizhijian@fujitsu.com>,
Leonardo Bras <leobras@redhat.com>,
Eric Blake <eblake@redhat.com>, Fabiano Rosas <farosas@suse.de>
Subject: [PULL 40/65] migration/rdma: Fix error handling around rdma_getaddrinfo()
Date: Wed, 11 Oct 2023 11:21:38 +0200 [thread overview]
Message-ID: <20231011092203.1266-41-quintela@redhat.com> (raw)
In-Reply-To: <20231011092203.1266-1-quintela@redhat.com>
From: Markus Armbruster <armbru@redhat.com>
qemu_rdma_resolve_host() and qemu_rdma_dest_init() iterate over
addresses to find one that works, holding onto the first Error from
qemu_rdma_broken_ipv6_kernel() for use when no address works. Issues:
1. If @errp was &error_abort or &error_fatal, we'd terminate instead
of trying the next address. Can't actually happen, since no caller
passes these arguments.
2. When @errp is a pointer to a variable containing NULL, and
qemu_rdma_broken_ipv6_kernel() fails, the variable no longer
contains NULL. Subsequent iterations pass it again, violating
Error usage rules. Dangerous, as setting an error would then trip
error_setv()'s assertion. Works only because
qemu_rdma_broken_ipv6_kernel() and the code following the loops
carefully avoids setting a second error.
3. If qemu_rdma_broken_ipv6_kernel() fails, and then a later iteration
finds a working address, @errp still holds the first error from
qemu_rdma_broken_ipv6_kernel(). If we then run into another error,
we report the qemu_rdma_broken_ipv6_kernel() failure instead.
4. If we don't run into another error, we leak the Error object.
Use a local error variable, and propagate to @errp. This fixes 3. and
also cleans up 1 and partly 2.
Free this error when we have a working address. This fixes 4.
Pass the local error variable to qemu_rdma_broken_ipv6_kernel() only
until it fails. Pass null on any later iterations. This cleans up
the remainder of 2.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20230928132019.2544702-34-armbru@redhat.com>
---
migration/rdma.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/migration/rdma.c b/migration/rdma.c
index 4074509f06..3fb899f963 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -932,6 +932,7 @@ static int qemu_rdma_broken_ipv6_kernel(struct ibv_context *verbs, Error **errp)
*/
static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
{
+ Error *err = NULL;
int ret;
struct rdma_addrinfo *res;
char port_str[16];
@@ -976,7 +977,10 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
goto err_resolve_get_addr;
}
+ /* Try all addresses, saving the first error in @err */
for (e = res; e != NULL; e = e->ai_next) {
+ Error **local_errp = err ? NULL : &err;
+
inet_ntop(e->ai_family,
&((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);
trace_qemu_rdma_resolve_host_trying(rdma->host, ip);
@@ -985,17 +989,21 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp)
RDMA_RESOLVE_TIMEOUT_MS);
if (ret >= 0) {
if (e->ai_family == AF_INET6) {
- ret = qemu_rdma_broken_ipv6_kernel(rdma->cm_id->verbs, errp);
+ ret = qemu_rdma_broken_ipv6_kernel(rdma->cm_id->verbs,
+ local_errp);
if (ret < 0) {
continue;
}
}
+ error_free(err);
goto route;
}
}
rdma_freeaddrinfo(res);
- if (errp && !*errp) {
+ if (err) {
+ error_propagate(errp, err);
+ } else {
error_setg(errp, "RDMA ERROR: could not resolve address %s",
rdma->host);
}
@@ -2707,6 +2715,7 @@ err_rdma_source_connect:
static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
{
+ Error *err = NULL;
int ret, idx;
struct rdma_cm_id *listen_id;
char ip[40] = "unknown";
@@ -2765,7 +2774,11 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
}
goto err_dest_init_bind_addr;
}
+
+ /* Try all addresses, saving the first error in @err */
for (e = res; e != NULL; e = e->ai_next) {
+ Error **local_errp = err ? NULL : &err;
+
inet_ntop(e->ai_family,
&((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);
trace_qemu_rdma_dest_init_trying(rdma->host, ip);
@@ -2774,17 +2787,21 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)
continue;
}
if (e->ai_family == AF_INET6) {
- ret = qemu_rdma_broken_ipv6_kernel(listen_id->verbs, errp);
+ ret = qemu_rdma_broken_ipv6_kernel(listen_id->verbs,
+ local_errp);
if (ret < 0) {
continue;
}
}
+ error_free(err);
break;
}
rdma_freeaddrinfo(res);
if (!e) {
- if (errp && !*errp) {
+ if (err) {
+ error_propagate(errp, err);
+ } else {
error_setg(errp, "RDMA ERROR: Error: could not rdma_bind_addr!");
}
goto err_dest_init_bind_addr;
--
2.41.0
next prev parent reply other threads:[~2023-10-11 9:34 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-11 9:20 [PULL 00/65] Migration 20231011 patches Juan Quintela
2023-10-11 9:20 ` [PULL 01/65] migration/qmp: Fix crash on setting tls-authz with null Juan Quintela
2023-10-11 9:21 ` [PULL 02/65] tests/qtest: migration: Expose migrate_set_capability Juan Quintela
2023-10-11 9:21 ` [PULL 03/65] tests/qtest: migration: Add migrate_incoming_qmp helper Juan Quintela
2023-10-11 9:21 ` [PULL 04/65] tests/qtest: migration: Use migrate_incoming_qmp where appropriate Juan Quintela
2023-10-11 9:21 ` [PULL 05/65] migration: Set migration status early in incoming side Juan Quintela
2023-10-11 9:21 ` [PULL 06/65] tests/qtest: migration: Add support for negative testing of qmp_migrate Juan Quintela
2023-10-11 13:04 ` Fabiano Rosas
2023-10-11 14:11 ` Juan Quintela
2023-10-11 20:30 ` Juan Quintela
2023-10-11 9:21 ` [PULL 07/65] migration: Allow RECOVER->PAUSED convertion for dest qemu Juan Quintela
2023-10-11 9:21 ` [PULL 08/65] migration/rdma: Clean up qemu_rdma_poll()'s return type Juan Quintela
2023-10-11 9:21 ` [PULL 09/65] migration/rdma: Clean up qemu_rdma_data_init()'s " Juan Quintela
2023-10-11 9:21 ` [PULL 10/65] migration/rdma: Clean up rdma_delete_block()'s " Juan Quintela
2023-10-11 9:21 ` [PULL 11/65] migration/rdma: Drop fragile wr_id formatting Juan Quintela
2023-10-11 9:21 ` [PULL 12/65] migration/rdma: Consistently use uint64_t for work request IDs Juan Quintela
2023-10-11 9:21 ` [PULL 13/65] migration/rdma: Fix unwanted integer truncation Juan Quintela
2023-10-11 9:21 ` [PULL 14/65] migration/rdma: Clean up two more harmless signed vs. unsigned issues Juan Quintela
2023-10-11 9:21 ` [PULL 15/65] migration/rdma: Give qio_channel_rdma_source_funcs internal linkage Juan Quintela
2023-10-11 9:21 ` [PULL 16/65] migration/rdma: Fix qemu_rdma_accept() to return failure on errors Juan Quintela
2023-10-11 9:21 ` [PULL 17/65] migration/rdma: Put @errp parameter last Juan Quintela
2023-10-11 9:21 ` [PULL 18/65] migration/rdma: Eliminate error_propagate() Juan Quintela
2023-10-11 9:21 ` [PULL 19/65] migration/rdma: Drop rdma_add_block() error handling Juan Quintela
2023-10-11 9:21 ` [PULL 20/65] migration/rdma: Drop qemu_rdma_search_ram_block() " Juan Quintela
2023-10-11 9:21 ` [PULL 21/65] migration/rdma: Make qemu_rdma_buffer_mergeable() return bool Juan Quintela
2023-10-11 9:21 ` [PULL 22/65] migration/rdma: Use bool for two RDMAContext flags Juan Quintela
2023-10-11 9:21 ` [PULL 23/65] migration/rdma: Fix or document problematic uses of errno Juan Quintela
2023-10-11 9:21 ` [PULL 24/65] migration/rdma: Ditch useless numeric error codes in error messages Juan Quintela
2023-10-11 9:21 ` [PULL 25/65] migration/rdma: Fix io_writev(), io_readv() methods to obey contract Juan Quintela
2023-10-11 9:21 ` [PULL 26/65] migration/rdma: Replace dangerous macro CHECK_ERROR_STATE() Juan Quintela
2023-10-11 9:21 ` [PULL 27/65] migration/rdma: Fix qemu_rdma_broken_ipv6_kernel() to set error Juan Quintela
2023-10-11 9:21 ` [PULL 28/65] migration/rdma: Fix qemu_get_cm_event_timeout() to always " Juan Quintela
2023-10-11 9:21 ` [PULL 29/65] migration/rdma: Drop dead qemu_rdma_data_init() code for !@host_port Juan Quintela
2023-10-11 9:21 ` [PULL 30/65] migration/rdma: Fix QEMUFileHooks method return values Juan Quintela
2023-10-11 9:21 ` [PULL 31/65] migration/rdma: Fix rdma_getaddrinfo() error checking Juan Quintela
2023-10-11 9:21 ` [PULL 32/65] migration/rdma: Return -1 instead of negative errno code Juan Quintela
2023-10-11 9:21 ` [PULL 33/65] migration/rdma: Dumb down remaining int error values to -1 Juan Quintela
2023-10-11 9:21 ` [PULL 34/65] migration/rdma: Replace int error_state by bool errored Juan Quintela
2023-10-11 9:21 ` [PULL 35/65] migration/rdma: Drop superfluous assignments to @ret Juan Quintela
2023-10-11 9:21 ` [PULL 36/65] migration/rdma: Check negative error values the same way everywhere Juan Quintela
2023-10-11 9:21 ` [PULL 37/65] migration/rdma: Plug a memory leak and improve a message Juan Quintela
2023-10-11 9:21 ` [PULL 38/65] migration/rdma: Delete inappropriate error_report() in macro ERROR() Juan Quintela
2023-10-11 9:21 ` [PULL 39/65] migration/rdma: Retire " Juan Quintela
2023-10-11 9:21 ` Juan Quintela [this message]
2023-10-11 9:21 ` [PULL 41/65] migration/rdma: Drop "@errp is clear" guards around error_setg() Juan Quintela
2023-10-11 9:21 ` [PULL 42/65] migration/rdma: Convert qemu_rdma_exchange_recv() to Error Juan Quintela
2023-10-11 9:21 ` [PULL 43/65] migration/rdma: Convert qemu_rdma_exchange_send() " Juan Quintela
2023-10-11 9:21 ` [PULL 44/65] migration/rdma: Convert qemu_rdma_exchange_get_response() " Juan Quintela
2023-10-11 9:21 ` [PULL 45/65] migration/rdma: Convert qemu_rdma_reg_whole_ram_blocks() " Juan Quintela
2023-10-11 9:21 ` [PULL 46/65] migration/rdma: Convert qemu_rdma_write_flush() " Juan Quintela
2023-10-11 9:21 ` [PULL 47/65] migration/rdma: Convert qemu_rdma_write_one() " Juan Quintela
2023-10-11 9:21 ` [PULL 48/65] migration/rdma: Convert qemu_rdma_write() " Juan Quintela
2023-10-11 9:21 ` [PULL 49/65] migration/rdma: Convert qemu_rdma_post_send_control() " Juan Quintela
2023-10-11 9:21 ` [PULL 50/65] migration/rdma: Convert qemu_rdma_post_recv_control() " Juan Quintela
2023-10-11 9:21 ` [PULL 51/65] migration/rdma: Convert qemu_rdma_alloc_pd_cq() " Juan Quintela
2023-10-11 9:21 ` [PULL 52/65] migration/rdma: Silence qemu_rdma_resolve_host() Juan Quintela
2023-10-11 9:21 ` [PULL 53/65] migration/rdma: Silence qemu_rdma_connect() Juan Quintela
2023-10-11 9:21 ` [PULL 54/65] migration/rdma: Silence qemu_rdma_reg_control() Juan Quintela
2023-10-11 9:21 ` [PULL 55/65] migration/rdma: Don't report received completion events as error Juan Quintela
2023-10-11 9:21 ` [PULL 56/65] migration/rdma: Silence qemu_rdma_block_for_wrid() Juan Quintela
2023-10-11 9:21 ` [PULL 57/65] migration/rdma: Silence qemu_rdma_register_and_get_keys() Juan Quintela
2023-10-11 9:21 ` [PULL 58/65] migration/rdma: Downgrade qemu_rdma_cleanup() errors to warnings Juan Quintela
2023-10-11 9:21 ` [PULL 59/65] migration/rdma: Use error_report() & friends instead of stderr Juan Quintela
2023-10-11 9:21 ` [PULL 60/65] migration/rdma: Replace flawed device detail dump by tracing Juan Quintela
2023-10-11 9:21 ` [PULL 61/65] migration: Display error in query-migrate irrelevant of status Juan Quintela
2023-10-11 9:22 ` [PULL 62/65] migration: Introduce migrate_has_error() Juan Quintela
2023-10-11 9:22 ` [PULL 63/65] qemufile: Always return a verbose error Juan Quintela
2023-10-11 9:22 ` [PULL 64/65] migration: Remember num of ramblocks to sync during recovery Juan Quintela
2023-10-11 9:22 ` [PULL 65/65] migration: Add migration_rp_wait|kick() Juan Quintela
2023-10-11 17:04 ` [PULL 00/65] Migration 20231011 patches Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231011092203.1266-41-quintela@redhat.com \
--to=quintela@redhat.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=farosas@suse.de \
--cc=leobras@redhat.com \
--cc=lizhijian@fujitsu.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).