From nobody Wed Nov 27 14:38:59 2024 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=1699013210; cv=none; d=zohomail.com; s=zohoarc; b=BKxr2lLOh4Lwm88xx71yoMZ/GiqS7Jo5Arc4AbSAAFBnUkEAYtFuh53tfbvgiKxqOOsauSrdQKsye6z5XciD2WowobyNd+8sMf0GBKLzS5oGy4LS7S1yoBxvyOTxgp/qRK4M5Nztgo800UsDYU+/HxT+YWZATE1mMLTu5ivbozw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699013210; h=Content-Type: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=Po37/l/PnN1kE4BKj/BqCDJtnhPBibDBhhPnhzgrvoQ=; b=cnREMBUElmJkL5+N2EwgRqPUvazjOBoQ9sSzSZT+6yyWrCoy2UtYJpOjwIdWQ+LzcPZF3Ma6KgSPttz2zUjbWP1E2gZi2pG4iXwRYRJ6QAd4FnSBkhcxcg5o5xIsJ1b/lEQ7jKWjWzZOqG9c+HfpQcFo0fRs/ekQCCCGiVBiTLA= 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 169901321051749.838690511142545; Fri, 3 Nov 2023 05:06:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qysvn-0007um-Hk; Fri, 03 Nov 2023 08:05:43 -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 1qysvM-0007Xk-52 for qemu-devel@nongnu.org; Fri, 03 Nov 2023 08:05:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qysvI-0001f4-SR for qemu-devel@nongnu.org; Fri, 03 Nov 2023 08:05:15 -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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-WX0z8KULNASgPld8e0hcjg-1; Fri, 03 Nov 2023 08:05:08 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DCB2385A59D; Fri, 3 Nov 2023 12:05:04 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F2FC492BE0; Fri, 3 Nov 2023 12:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699013111; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Po37/l/PnN1kE4BKj/BqCDJtnhPBibDBhhPnhzgrvoQ=; b=Vakv9sam2pieukPaRm36bL5i4XiqSTmx9A2CPaHN2O9OVI2kWSMfnpzo9zTsXzNpRvgCr9 tsOJFivsoaPW4ut43P/shAcxbEqbla3sN+QUD/ncRcFFqktMKoeuy4cw25NFv6TPltvLiO AWQYy+oB0+X69hE3PBnUS8yYC/P4WWU= X-MC-Unique: WX0z8KULNASgPld8e0hcjg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Hyman Huang , Thomas Huth , Peter Xu , Paolo Bonzini , Fabiano Rosas , Laurent Vivier , Juan Quintela , Leonardo Bras , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PULL 7/7] migration: Unlock mutex in error case Date: Fri, 3 Nov 2023 13:04:48 +0100 Message-ID: <20231103120448.58428-8-quintela@redhat.com> In-Reply-To: <20231103120448.58428-1-quintela@redhat.com> References: <20231103120448.58428-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.47, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1699013212475100001 We were not unlocking bitmap mutex on the error case. To fix it forever change to enclose the code with WITH_QEMU_LOCK_GUARD(). Coverity CID 1523750. Fixes: a2326705e5 ("migration: Stop migration immediately in RDMA error pat= hs") Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Juan Quintela Message-ID: <20231103074245.55166-1-quintela@redhat.com> --- migration/ram.c | 106 ++++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index a0f3b86663..8c7886ab79 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3030,71 +3030,71 @@ static int ram_save_iterate(QEMUFile *f, void *opaq= ue) * MAX_WAIT (if curious, further see commit 4508bd9ed8053ce) below, wh= ich * guarantees that we'll at least released it in a regular basis. */ - qemu_mutex_lock(&rs->bitmap_mutex); - WITH_RCU_READ_LOCK_GUARD() { - if (ram_list.version !=3D rs->last_version) { - ram_state_reset(rs); - } - - /* Read version before ram_list.blocks */ - smp_rmb(); - - ret =3D rdma_registration_start(f, RAM_CONTROL_ROUND); - if (ret < 0) { - qemu_file_set_error(f, ret); - goto out; - } - - t0 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); - i =3D 0; - while ((ret =3D migration_rate_exceeded(f)) =3D=3D 0 || - postcopy_has_request(rs)) { - int pages; - - if (qemu_file_get_error(f)) { - break; + WITH_QEMU_LOCK_GUARD(&rs->bitmap_mutex) { + WITH_RCU_READ_LOCK_GUARD() { + if (ram_list.version !=3D rs->last_version) { + ram_state_reset(rs); } =20 - pages =3D ram_find_and_save_block(rs); - /* no more pages to sent */ - if (pages =3D=3D 0) { - done =3D 1; - break; - } + /* Read version before ram_list.blocks */ + smp_rmb(); =20 - if (pages < 0) { - qemu_file_set_error(f, pages); - break; + ret =3D rdma_registration_start(f, RAM_CONTROL_ROUND); + if (ret < 0) { + qemu_file_set_error(f, ret); + goto out; } =20 - rs->target_page_count +=3D pages; + t0 =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); + i =3D 0; + while ((ret =3D migration_rate_exceeded(f)) =3D=3D 0 || + postcopy_has_request(rs)) { + int pages; =20 - /* - * During postcopy, it is necessary to make sure one whole host - * page is sent in one chunk. - */ - if (migrate_postcopy_ram()) { - compress_flush_data(); - } + if (qemu_file_get_error(f)) { + break; + } + + pages =3D ram_find_and_save_block(rs); + /* no more pages to sent */ + if (pages =3D=3D 0) { + done =3D 1; + break; + } =20 - /* - * we want to check in the 1st loop, just in case it was the 1= st - * time and we had to sync the dirty bitmap. - * qemu_clock_get_ns() is a bit expensive, so we only check ea= ch - * some iterations - */ - if ((i & 63) =3D=3D 0) { - uint64_t t1 =3D (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - = t0) / - 1000000; - if (t1 > MAX_WAIT) { - trace_ram_save_iterate_big_wait(t1, i); + if (pages < 0) { + qemu_file_set_error(f, pages); break; } + + rs->target_page_count +=3D pages; + + /* + * During postcopy, it is necessary to make sure one whole= host + * page is sent in one chunk. + */ + if (migrate_postcopy_ram()) { + compress_flush_data(); + } + + /* + * we want to check in the 1st loop, just in case it was t= he 1st + * time and we had to sync the dirty bitmap. + * qemu_clock_get_ns() is a bit expensive, so we only chec= k each + * some iterations + */ + if ((i & 63) =3D=3D 0) { + uint64_t t1 =3D (qemu_clock_get_ns(QEMU_CLOCK_REALTIME= ) - t0) / + 1000000; + if (t1 > MAX_WAIT) { + trace_ram_save_iterate_big_wait(t1, i); + break; + } + } + i++; } - i++; } } - qemu_mutex_unlock(&rs->bitmap_mutex); =20 /* * Must occur before EOS (or any QEMUFile operation) --=20 2.41.0