From nobody Tue Feb 10 11:55:35 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1697016702; cv=none; d=zohomail.com; s=zohoarc; b=aUZv05eYUAYVzWbsUeZnTWQgadQ+Z3vQ3Gq1bnC8yQbVpCdJnYHe5twDHhwOnPnSf4Pw1+XxurYFDDsPmh9Gm80UAUxpgsMlpTIcTimMLhKjJxEqIvUqafaLdvM2SVG/PdqDVLQVQyD6MBJ+qd0T5a7k0f4S8GzKnawxWwEex0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1697016702; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=2mI9cvJ38Esr8uD9Yjy13Nuxs++2Zmm4Rrvjvm1oYXs=; b=VrYpAK6+cF1baYhOtzXGxctzzCO1aQv5nz2gaG21cW2YOlyC8QmPkON7OlqcL8nIgkCdJsr1UUeHsrhGZb7D23FQs83pZyJOke9gZ+SSG1m3XCJDbqb3o5WTH25EgYJULUuV+42A6y9YGcAAnJWiRmipAMVGB3kJFX0L6zyJbeY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1697016702556999.8679576412974; Wed, 11 Oct 2023 02:31:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qqVR8-0008HB-Je; Wed, 11 Oct 2023 05:23:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqVR3-0007bv-FU for qemu-devel@nongnu.org; Wed, 11 Oct 2023 05:23:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qqVR1-00051k-L7 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 05:23:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-651-nJeRzTyoO_acGBSt49uUxA-1; Wed, 11 Oct 2023 05:23:07 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B2FD801E91; Wed, 11 Oct 2023 09:23:07 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F0E31C060AE; Wed, 11 Oct 2023 09:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697016199; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2mI9cvJ38Esr8uD9Yjy13Nuxs++2Zmm4Rrvjvm1oYXs=; b=R0UqGvPEAwq9gW37M1XuD8bHIvbmFKLjQc8WCBOXRIg8tLxRiEFR3dAnNvBKG6yJswhbd6 qgE5eDEDF2+XW3RfKlpKlb/eQ5UNyApvOLNIKkqGGX8Vq6qZFEenTe7kNEN515JobQNLdy UbeDtglm7ImcBblKwmb0WpW1oDA1FNA= X-MC-Unique: nJeRzTyoO_acGBSt49uUxA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Laurent Vivier , Peter Xu , Paolo Bonzini , Markus Armbruster , Juan Quintela , Thomas Huth , Li Zhijian , Leonardo Bras , Eric Blake , Fabiano Rosas Subject: [PULL 30/65] migration/rdma: Fix QEMUFileHooks method return values Date: Wed, 11 Oct 2023 11:21:28 +0200 Message-ID: <20231011092203.1266-31-quintela@redhat.com> In-Reply-To: <20231011092203.1266-1-quintela@redhat.com> References: <20231011092203.1266-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1697016704019100006 Content-Type: text/plain; charset="utf-8" From: Markus Armbruster The QEMUFileHooks methods don't come with a written contract. Digging through the code calling them, we find: * save_page(): Negative values RAM_SAVE_CONTROL_DELAYED and RAM_SAVE_CONTROL_NOT_SUPP are special. Any other negative value is an unspecified error. qemu_rdma_save_page() returns -EIO or rdma->error_state on error. I believe the latter is always negative. Nothing stops either of them to clash with the special values, though. Feels unlikely, but fix it anyway to return only the special values and -1. * before_ram_iterate(), after_ram_iterate(): Negative value means error. qemu_rdma_registration_start() and qemu_rdma_registration_stop() comply as far as I can tell. Make them comply *obviously*, by returning -1 on error. * hook_ram_load: Negative value means error. rdma_load_hook() already returns -1 on error. Leave it alone. Signed-off-by: Markus Armbruster Reviewed-by: Li Zhijian Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela Message-ID: <20230928132019.2544702-24-armbru@redhat.com> --- migration/rdma.c | 79 +++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 55eb8222ea..974edde6a3 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3268,12 +3268,11 @@ static int qemu_rdma_save_page(QEMUFile *f, ram_add= r_t block_offset, rdma =3D qatomic_rcu_read(&rioc->rdmaout); =20 if (!rdma) { - return -EIO; + return -1; } =20 - ret =3D check_error_state(rdma); - if (ret) { - return ret; + if (check_error_state(rdma)) { + return -1; } =20 qemu_fflush(f); @@ -3329,9 +3328,10 @@ static int qemu_rdma_save_page(QEMUFile *f, ram_addr= _t block_offset, } =20 return RAM_SAVE_CONTROL_DELAYED; + err: rdma->error_state =3D ret; - return ret; + return -1; } =20 static void rdma_accept_incoming_migration(void *opaque); @@ -3577,12 +3577,11 @@ static int qemu_rdma_registration_handle(QEMUFile *= f) rdma =3D qatomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - return -EIO; + return -1; } =20 - ret =3D check_error_state(rdma); - if (ret) { - return ret; + if (check_error_state(rdma)) { + return -1; } =20 local =3D &rdma->local_ram_blocks; @@ -3615,7 +3614,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) (unsigned int)comp->block_idx, rdma->local_ram_blocks.nb_blocks); ret =3D -EIO; - goto out; + goto err; } block =3D &(rdma->local_ram_blocks.block[comp->block_idx]); =20 @@ -3627,7 +3626,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) =20 case RDMA_CONTROL_REGISTER_FINISHED: trace_qemu_rdma_registration_handle_finished(); - goto out; + return 0; =20 case RDMA_CONTROL_RAM_BLOCKS_REQUEST: trace_qemu_rdma_registration_handle_ram_blocks(); @@ -3648,7 +3647,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) if (ret) { error_report("rdma migration: error dest " "registering ram blocks"); - goto out; + goto err; } } =20 @@ -3687,7 +3686,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) =20 if (ret < 0) { error_report("rdma migration: error sending remote info"); - goto out; + goto err; } =20 break; @@ -3714,7 +3713,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) (unsigned int)reg->current_index, rdma->local_ram_blocks.nb_blocks); ret =3D -ENOENT; - goto out; + goto err; } block =3D &(rdma->local_ram_blocks.block[reg->current_inde= x]); if (block->is_ram_block) { @@ -3724,7 +3723,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) block->block_name, block->offset, reg->key.current_addr); ret =3D -ERANGE; - goto out; + goto err; } host_addr =3D (block->local_host_addr + (reg->key.current_addr - block->offset)); @@ -3740,7 +3739,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) " chunk: %" PRIx64, block->block_name, reg->key.chunk); ret =3D -ERANGE; - goto out; + goto err; } } chunk_start =3D ram_chunk_start(block, chunk); @@ -3752,7 +3751,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) chunk, chunk_start, chunk_end)) { error_report("cannot get rkey"); ret =3D -EINVAL; - goto out; + goto err; } reg_result->rkey =3D tmp_rkey; =20 @@ -3769,7 +3768,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) =20 if (ret < 0) { error_report("Failed to send control buffer"); - goto out; + goto err; } break; case RDMA_CONTROL_UNREGISTER_REQUEST: @@ -3792,7 +3791,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f) if (ret !=3D 0) { perror("rdma unregistration chunk failed"); ret =3D -ret; - goto out; + goto err; } =20 rdma->total_registrations--; @@ -3805,24 +3804,23 @@ static int qemu_rdma_registration_handle(QEMUFile *= f) =20 if (ret < 0) { error_report("Failed to send control buffer"); - goto out; + goto err; } break; case RDMA_CONTROL_REGISTER_RESULT: error_report("Invalid RESULT message at dest."); ret =3D -EIO; - goto out; + goto err; default: error_report("Unknown control message %s", control_desc(head.t= ype)); ret =3D -EIO; - goto out; + goto err; } } while (1); -out: - if (ret < 0) { - rdma->error_state =3D ret; - } - return ret; + +err: + rdma->error_state =3D ret; + return -1; } =20 /* Destination: @@ -3844,7 +3842,7 @@ rdma_block_notification_handle(QEMUFile *f, const cha= r *name) rdma =3D qatomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - return -EIO; + return -1; } =20 /* Find the matching RAMBlock in our local list */ @@ -3857,7 +3855,7 @@ rdma_block_notification_handle(QEMUFile *f, const cha= r *name) =20 if (found =3D=3D -1) { error_report("RAMBlock '%s' not found on destination", name); - return -ENOENT; + return -1; } =20 rdma->local_ram_blocks.block[curr].src_index =3D rdma->next_src_index; @@ -3887,7 +3885,6 @@ static int qemu_rdma_registration_start(QEMUFile *f, { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(qemu_file_get_ioc(f)); RDMAContext *rdma; - int ret; =20 if (migration_in_postcopy()) { return 0; @@ -3896,12 +3893,11 @@ static int qemu_rdma_registration_start(QEMUFile *f, RCU_READ_LOCK_GUARD(); rdma =3D qatomic_rcu_read(&rioc->rdmaout); if (!rdma) { - return -EIO; + return -1; } =20 - ret =3D check_error_state(rdma); - if (ret) { - return ret; + if (check_error_state(rdma)) { + return -1; } =20 trace_qemu_rdma_registration_start(flags); @@ -3930,12 +3926,11 @@ static int qemu_rdma_registration_stop(QEMUFile *f, RCU_READ_LOCK_GUARD(); rdma =3D qatomic_rcu_read(&rioc->rdmaout); if (!rdma) { - return -EIO; + return -1; } =20 - ret =3D check_error_state(rdma); - if (ret) { - return ret; + if (check_error_state(rdma)) { + return -1; } =20 qemu_fflush(f); @@ -3966,7 +3961,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, qemu_rdma_reg_whole_ram_blocks : NULL); if (ret < 0) { fprintf(stderr, "receiving remote info!"); - return ret; + return -1; } =20 nb_dest_blocks =3D resp.len / sizeof(RDMADestBlock); @@ -3989,7 +3984,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, "not identical on both the source and destination.", local->nb_blocks, nb_dest_blocks); rdma->error_state =3D -EINVAL; - return -EINVAL; + return -1; } =20 qemu_rdma_move_header(rdma, reg_result_idx, &resp); @@ -4005,7 +4000,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, local->block[i].length, rdma->dest_blocks[i].length); rdma->error_state =3D -EINVAL; - return -EINVAL; + return -1; } local->block[i].remote_host_addr =3D rdma->dest_blocks[i].remote_host_addr; @@ -4025,7 +4020,7 @@ static int qemu_rdma_registration_stop(QEMUFile *f, return 0; err: rdma->error_state =3D ret; - return ret; + return -1; } =20 static const QEMUFileHooks rdma_read_hooks =3D { --=20 2.41.0