From nobody Fri May 17 06:07:56 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=1681335993; cv=none; d=zohomail.com; s=zohoarc; b=lOIS7FnTxqcaaljTO+UL2EzqDsO/VZEIZaa0sb2Qtt1VqpMFVv9Br+PS9wDpmOwFE2CIQGdXMANuqDlfjNgR4g3cd5aux00A+LHaBtw0M87kWE0P7dsGRTXfNg/PYBDNuZNvT8ehEzGTRml8Npff11noDjazAPmz54isUTgI28c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681335993; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZcwNAcxsP5avnR9qInovHQVmt6wLpJO6hu/KQ1QQQUQ=; b=Vsik/9XZ94NKDRmX4sC425SnuBqf5FbFbudgjMcApKwHYTY+cI2tDgfgyEbS/m2/tNzzDTPzC/KQvklqZWRvMPn5QYvg6MNZztOAsO+GyoqFlY8ehYNT8nTiP+Iqnf7757XffByOd22G+39mviLsKNVGgpYemt2j5DWBM2KOXac= 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 1681335993347103.33541041962042; Wed, 12 Apr 2023 14:46:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmiHL-0008MY-Ft; Wed, 12 Apr 2023 17:45:23 -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 1pmiHJ-0008Ly-BW for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:21 -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 1pmiHH-0006Zv-8F for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:20 -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-520-OF0QqyBJPPi8FBjZA_hfPw-1; Wed, 12 Apr 2023 17:45:12 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEE71185A78F; Wed, 12 Apr 2023 21:45:11 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CA601121320; Wed, 12 Apr 2023 21:45:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681335916; 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=ZcwNAcxsP5avnR9qInovHQVmt6wLpJO6hu/KQ1QQQUQ=; b=PjiEfNwZMRLH+3ak2Z6GNFJ9iXE9TNl9OrlQYATf0D+37Y3lMpbrHGcOSY8nzoXjtfTwBV OpaQtql4FcmHvNRbZOYUvzruvChzA2YlV0RmUVEcVzzZVaU5CiRHeQjEYkDzecsgzA1jcO e645Pjk6zXsiiYinDt6u4uLfSQzBOAU= X-MC-Unique: OF0QqyBJPPi8FBjZA_hfPw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu Subject: [PULL 1/5] io: tls: Inherit QIO_CHANNEL_FEATURE_SHUTDOWN on server side Date: Wed, 12 Apr 2023 23:45:03 +0200 Message-Id: <20230412214507.19816-2-quintela@redhat.com> In-Reply-To: <20230412214507.19816-1-quintela@redhat.com> References: <20230412214507.19816-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.1 on 10.11.54.3 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: -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_H2=-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: 1681335994681100003 From: Peter Xu TLS iochannel will inherit io_shutdown() from the master ioc, however we missed to do that on the server side. This will e.g. allow qemu_file_shutdown() to work on dest QEMU too for migration. Acked-by: Daniel P. Berrang=C3=A9 Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- io/channel-tls.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/io/channel-tls.c b/io/channel-tls.c index 5a7a3d48d6..9805dd0a3f 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -74,6 +74,9 @@ qio_channel_tls_new_server(QIOChannel *master, ioc =3D QIO_CHANNEL_TLS(object_new(TYPE_QIO_CHANNEL_TLS)); =20 ioc->master =3D master; + if (qio_channel_has_feature(master, QIO_CHANNEL_FEATURE_SHUTDOWN)) { + qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SHUT= DOWN); + } object_ref(OBJECT(master)); =20 ioc->session =3D qcrypto_tls_session_new( --=20 2.39.2 From nobody Fri May 17 06:07:56 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=1681336009; cv=none; d=zohomail.com; s=zohoarc; b=CU4H4OsEtJn1qieIZN/gYMWHFWL7FzDa30bKxgXq07bK9EAG17O4Qk28VSyKTgcemnltuLkAL+oDtBvv1iF1f8j6jtyMWh1N8LkXMXZygHLbFQI0/+b/n0ppx0QM+7N8+Vm3JC4RycSjQutK0kro3FLK6AMC1NGbew6bLs8FBMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681336009; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aOAts4EQWeMp5FtVkuj19suf6clyIKQzyY2dHDTLld0=; b=HDqR+0k370Hs9boWrhsw82xzCLOp5kd+sKpbsUz/ZRusL/ICd4FwxPTx1qQ2/cEVGdGpkMM9Ib3816+PmyvKA+D+ysUKIBq12g9P9S/gU7GE04d1ifTxiPWBY97BP90NpwaSfDxKohQPsC3UxnT2BBXRGcjqGPgSOLrQx/yCl5o= 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 1681336009145743.7202488762234; Wed, 12 Apr 2023 14:46:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmiHL-0008MU-6w; Wed, 12 Apr 2023 17:45:23 -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 1pmiHJ-0008Lz-CD for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45: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 1pmiHH-0006aM-8A for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:21 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-P5J1PEOHNJ-TIp_J8ZChqQ-1; Wed, 12 Apr 2023 17:45:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3D271C04B77; Wed, 12 Apr 2023 21:45:13 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FEB71121320; Wed, 12 Apr 2023 21:45:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681335918; 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=aOAts4EQWeMp5FtVkuj19suf6clyIKQzyY2dHDTLld0=; b=hyZRNHuV2sS66DGiolmQpKqMA1Gcm8Ba9+i4uskURPwYqanWCNiJKqsiU1Mei5yjK1K4hl gjjJ9ZNDbToCRwvvIrFSgwTnMz0ioJT7KPj7xxR6mP/Eyq8QQ1c1qvwa/pr8UWk654hQ2C umnuw6D2XmWhtw1LxqtQ1AZh4hO/U8E= X-MC-Unique: P5J1PEOHNJ-TIp_J8ZChqQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu Subject: [PULL 2/5] migration: Fix potential race on postcopy_qemufile_src Date: Wed, 12 Apr 2023 23:45:04 +0200 Message-Id: <20230412214507.19816-3-quintela@redhat.com> In-Reply-To: <20230412214507.19816-1-quintela@redhat.com> References: <20230412214507.19816-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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_H2=-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: 1681336009984100006 Content-Type: text/plain; charset="utf-8" From: Peter Xu postcopy_qemufile_src object should be owned by one thread, either the main thread (e.g. when at the beginning, or at the end of migration), or by the return path thread (when during a preempt enabled postcopy migration). If that's not the case the access to the object might be racy. postcopy_preempt_shutdown_file() can be potentially racy, because it's called at the end phase of migration on the main thread, however during which the return path thread hasn't yet been recycled; the recycle happens in await_return_path_close_on_source() which is after this point. It means, logically it's posslbe the main thread and the return path thread are both operating on the same qemufile. While I don't think qemufile is thread safe at all. postcopy_preempt_shutdown_file() used to be needed because that's where we send EOS to dest so that dest can safely shutdown the preempt thread. To avoid the possible race, remove this only place that a race can happen. Instead we figure out another way to safely close the preempt thread on dest. The core idea during postcopy on deciding "when to stop" is that dest will send a postcopy SHUT message to src, telling src that all data is there. Hence to shut the dest preempt thread maybe better to do it directly on dest node. This patch proposed such a way that we change postcopy_prio_thread_created into PreemptThreadStatus, so that we kick the preempt thread on dest qemu by a sequence of: mis->preempt_thread_status =3D PREEMPT_THREAD_QUIT; qemu_file_shutdown(mis->postcopy_qemufile_dst); While here shutdown() is probably so far the easiest way to kick preempt thread from a blocked qemu_get_be64(). Then it reads preempt_thread_status to make sure it's not a network failure but a willingness to quit the thread. We could have avoided that extra status but just rely on migration status. The problem is postcopy_ram_incoming_cleanup() is just called early enough so we're still during POSTCOPY_ACTIVE no matter what.. So just make it simple to have the status introduced. One flag x-preempt-pre-7-2 is added to keep old pre-7.2 behaviors of postcopy preempt. Fixes: 9358982744 ("migration: Send requested page directly in rp-return th= read") Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 34 +++++++++++++++++++++++++++++++++- hw/core/machine.c | 1 + migration/migration.c | 10 ++++++++-- migration/postcopy-ram.c | 20 +++++++++++++++----- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 2da2f8a164..67baba2184 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -65,6 +65,12 @@ typedef struct { bool all_zero; } PostcopyTmpPage; =20 +typedef enum { + PREEMPT_THREAD_NONE =3D 0, + PREEMPT_THREAD_CREATED, + PREEMPT_THREAD_QUIT, +} PreemptThreadStatus; + /* State for the incoming migration */ struct MigrationIncomingState { QEMUFile *from_src_file; @@ -124,7 +130,12 @@ struct MigrationIncomingState { QemuSemaphore postcopy_qemufile_dst_done; /* Postcopy priority thread is used to receive postcopy requested page= s */ QemuThread postcopy_prio_thread; - bool postcopy_prio_thread_created; + /* + * Always set by the main vm load thread only, but can be read by the + * postcopy preempt thread. "volatile" makes sure all reads will be + * uptodate across cores. + */ + volatile PreemptThreadStatus preempt_thread_status; /* * Used to sync between the ram load main thread and the fast ram load * thread. It protects postcopy_qemufile_dst, which is the postcopy @@ -364,6 +375,27 @@ struct MigrationState { * do not trigger spurious decompression errors. */ bool decompress_error_check; + /* + * This variable only affects behavior when postcopy preempt mode is + * enabled. + * + * When set: + * + * - postcopy preempt src QEMU instance will generate an EOS message at + * the end of migration to shut the preempt channel on dest side. + * + * When clear: + * + * - postcopy preempt src QEMU instance will _not_ generate an EOS + * message at the end of migration, the dest qemu will shutdown the + * channel itself. + * + * NOTE: See message-id on qemu-devel + * mailing list for more information on the possible race. Everyone + * should probably just keep this value untouched after set by the + * machine type (or the default). + */ + bool preempt_pre_7_2; =20 /* * This decides the size of guest memory chunk that will be used diff --git a/hw/core/machine.c b/hw/core/machine.c index 45e3d24fdc..cd13b8b0a3 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -42,6 +42,7 @@ GlobalProperty hw_compat_7_2[] =3D { { "e1000e", "migrate-timadj", "off" }, { "virtio-mem", "x-early-migration", "false" }, + { "migration", "x-preempt-pre-7-2", "true" }, }; const size_t hw_compat_7_2_len =3D G_N_ELEMENTS(hw_compat_7_2); =20 diff --git a/migration/migration.c b/migration/migration.c index ae2025d9d8..37fc4fb3e2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3464,8 +3464,12 @@ static void migration_completion(MigrationState *s) qemu_savevm_state_complete_postcopy(s->to_dst_file); qemu_mutex_unlock_iothread(); =20 - /* Shutdown the postcopy fast path thread */ - if (migrate_postcopy_preempt()) { + /* + * Shutdown the postcopy fast path thread. This is only needed + * when dest QEMU binary is old (7.1/7.2). QEMU 8.0+ doesn't need + * this. + */ + if (migrate_postcopy_preempt() && s->preempt_pre_7_2) { postcopy_preempt_shutdown_file(s); } =20 @@ -4443,6 +4447,8 @@ static Property migration_properties[] =3D { decompress_error_check, true), DEFINE_PROP_UINT8("x-clear-bitmap-shift", MigrationState, clear_bitmap_shift, CLEAR_BITMAP_SHIFT_DEFAULT), + DEFINE_PROP_BOOL("x-preempt-pre-7-2", MigrationState, + preempt_pre_7_2, false), =20 /* Migration parameters */ DEFINE_PROP_UINT8("x-compress-level", MigrationState, diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 41c0713650..263bab75ec 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -568,9 +568,14 @@ int postcopy_ram_incoming_cleanup(MigrationIncomingSta= te *mis) { trace_postcopy_ram_incoming_cleanup_entry(); =20 - if (mis->postcopy_prio_thread_created) { + if (mis->preempt_thread_status =3D=3D PREEMPT_THREAD_CREATED) { + /* Notify the fast load thread to quit */ + mis->preempt_thread_status =3D PREEMPT_THREAD_QUIT; + if (mis->postcopy_qemufile_dst) { + qemu_file_shutdown(mis->postcopy_qemufile_dst); + } qemu_thread_join(&mis->postcopy_prio_thread); - mis->postcopy_prio_thread_created =3D false; + mis->preempt_thread_status =3D PREEMPT_THREAD_NONE; } =20 if (mis->have_fault_thread) { @@ -1203,7 +1208,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingStat= e *mis) */ postcopy_thread_create(mis, &mis->postcopy_prio_thread, "fault-fas= t", postcopy_preempt_thread, QEMU_THREAD_JOINAB= LE); - mis->postcopy_prio_thread_created =3D true; + mis->preempt_thread_status =3D PREEMPT_THREAD_CREATED; } =20 trace_postcopy_ram_enable_notify(); @@ -1652,6 +1657,11 @@ static void postcopy_pause_ram_fast_load(MigrationIn= comingState *mis) trace_postcopy_pause_fast_load_continued(); } =20 +static bool preempt_thread_should_run(MigrationIncomingState *mis) +{ + return mis->preempt_thread_status !=3D PREEMPT_THREAD_QUIT; +} + void *postcopy_preempt_thread(void *opaque) { MigrationIncomingState *mis =3D opaque; @@ -1671,11 +1681,11 @@ void *postcopy_preempt_thread(void *opaque) =20 /* Sending RAM_SAVE_FLAG_EOS to terminate this thread */ qemu_mutex_lock(&mis->postcopy_prio_thread_mutex); - while (1) { + while (preempt_thread_should_run(mis)) { ret =3D ram_load_postcopy(mis->postcopy_qemufile_dst, RAM_CHANNEL_POSTCOPY); /* If error happened, go into recovery routine */ - if (ret) { + if (ret && preempt_thread_should_run(mis)) { postcopy_pause_ram_fast_load(mis); } else { /* We're done */ --=20 2.39.2 From nobody Fri May 17 06:07:56 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=1681336009; cv=none; d=zohomail.com; s=zohoarc; b=GFiG4ZccFCHOPI3ahyZ38POHGY47DvVx+tBpssqE9zg+NNBF0GfI5gm7LqVxJyPKmfraZzo87pEA74GuxRqc19fhtwpSqluPRkn+y3mfVNsYpAoJ5eQbhAnqwAIjGmGDjaKxtfJTYwl9evO//VOdTbKt+2XjwcyX3Kpq3kKU9zI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681336009; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4xXl3ct488HSIr4PQ2q8nI4ptvAg831yOJ2Mp5H618A=; b=Y/0AVJ6aLi/vKLRP71GgBAJ2Ze/cvvWvG+2l/cHnLdVjx0AOjJBlGkMtvD2xK0l03LMy0ANNTbXZhAeFTuOQV9VMWbBqSnJwaNtD+qgTG0HLp2gBp5TtgbhfprNZbqHITndqM0PsRjD2KsEwigqq33TG77jhECGJrayCh2antYU= 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 1681336009160373.46781535828575; Wed, 12 Apr 2023 14:46:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmiHM-0008ND-VJ; Wed, 12 Apr 2023 17:45:24 -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 1pmiHL-0008MV-7K for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:23 -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 1pmiHH-0006aT-Nl for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:22 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-187-5FnM4DV2PISLlnZtkAiTLA-1; Wed, 12 Apr 2023 17:45:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 37EE73C10EC1; Wed, 12 Apr 2023 21:45:15 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5F921121320; Wed, 12 Apr 2023 21:45:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681335918; 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=4xXl3ct488HSIr4PQ2q8nI4ptvAg831yOJ2Mp5H618A=; b=ezWnsNqBgRuMBMPQH0k8zWCSCuzUPux6LzN40FxYr2U/2wh/YNDWnEo20AQ4K3xMe3rtVv s52krq9gC9R5GpHqxtXo/penhUp0LGfqifhv69G6hBZrsjRPK0KV7VZ+Kg23TNS6TSSETc gumsy+FFSeht6EtpRvW/p+Q7lzG/I7Q= X-MC-Unique: 5FnM4DV2PISLlnZtkAiTLA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu Subject: [PULL 3/5] migration: Recover behavior of preempt channel creation for pre-7.2 Date: Wed, 12 Apr 2023 23:45:05 +0200 Message-Id: <20230412214507.19816-4-quintela@redhat.com> In-Reply-To: <20230412214507.19816-1-quintela@redhat.com> References: <20230412214507.19816-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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_H2=-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: 1681336009969100005 Content-Type: text/plain; charset="utf-8" From: Peter Xu In 8.0 devel window we reworked preempt channel creation, so that there'll be no race condition when the migration channel and preempt channel got established in the wrong order in commit 5655aab079. However no one noticed that the change will also be not compatible with older qemus, majorly 7.1/7.2 versions where preempt mode started to be supported. Leverage the same pre-7.2 flag introduced in the previous patch to recover the behavior hopefully before 8.0 releases, so we don't break migration when we migrate from 8.0 to older qemu binaries. Fixes: 5655aab079 ("migration: Postpone postcopy preempt channel to be afte= r main") Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 7 +++++++ migration/migration.c | 9 +++++++++ migration/postcopy-ram.c | 10 ++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 67baba2184..310ae8901b 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -384,12 +384,19 @@ struct MigrationState { * - postcopy preempt src QEMU instance will generate an EOS message at * the end of migration to shut the preempt channel on dest side. * + * - postcopy preempt channel will be created at the setup phase on src + QEMU. + * * When clear: * * - postcopy preempt src QEMU instance will _not_ generate an EOS * message at the end of migration, the dest qemu will shutdown the * channel itself. * + * - postcopy preempt channel will be created at the switching phase + * from precopy -> postcopy (to avoid race condtion of misordered + * creation of channels). + * * NOTE: See message-id on qemu-devel * mailing list for more information on the possible race. Everyone * should probably just keep this value untouched after set by the diff --git a/migration/migration.c b/migration/migration.c index 37fc4fb3e2..bda4789193 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4388,6 +4388,15 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) } } =20 + /* + * This needs to be done before resuming a postcopy. Note: for newer + * QEMUs we will delay the channel creation until postcopy_start(), to + * avoid disorder of channel creations. + */ + if (migrate_postcopy_preempt() && s->preempt_pre_7_2) { + postcopy_preempt_setup(s); + } + if (resume) { /* Wakeup the main migration thread to do the recovery */ migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED, diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 263bab75ec..93f39f8e06 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1630,8 +1630,14 @@ int postcopy_preempt_establish_channel(MigrationStat= e *s) return 0; } =20 - /* Kick off async task to establish preempt channel */ - postcopy_preempt_setup(s); + /* + * Kick off async task to establish preempt channel. Only do so with + * 8.0+ machines, because 7.1/7.2 require the channel to be created in + * setup phase of migration (even if racy in an unreliable network). + */ + if (!s->preempt_pre_7_2) { + postcopy_preempt_setup(s); + } =20 /* * We need the postcopy preempt channel to be established before --=20 2.39.2 From nobody Fri May 17 06:07:56 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=1681335987; cv=none; d=zohomail.com; s=zohoarc; b=WsgYgpaDdNosv1z1gSSuAl3koXl3/RMOeiUNPxmbx5UKYWYVj9NbAnu1RBjQHSInpUwp4tXfxB6KyPY8v9LH5yNgjRb3IpRcLweEQHzwt5cODtPieMm49jfdjPfsqjCh6Rn7IbtRKlg1DOBnrKXPqBwrTiFs0aiuGZrQIceNfjc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681335987; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=57ZIepROQQAFCGZsHrZ+1w8IXcpoRJewDTXcAxVlkAI=; b=GjekY0pZJ3mrPdjrIEmHLnj4GJE83B/p0mPCLFfPJTsKDdy8huofM4Yz6sNM/woWmdT9oKASWWyBFvg5MMHbEI90LtuAb1EptRkNbdtgYCMOOI5eYLCf7uviZuXaX1Gqx2kmz4Rm3Yxx27rkTp3WfAqyHSyG8lQ1l6ti+DjYw2Y= 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 1681335987573546.1220721947448; Wed, 12 Apr 2023 14:46:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmiHP-0008Nt-07; Wed, 12 Apr 2023 17:45:27 -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 1pmiHN-0008NE-2r for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:25 -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 1pmiHK-0006d3-VR for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:24 -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-608-9-DKE8TIOPWZUcM3IXo91w-1; Wed, 12 Apr 2023 17:45:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D1B9F85C06C; Wed, 12 Apr 2023 21:45:16 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78C3B112132D; Wed, 12 Apr 2023 21:45:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681335921; 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=57ZIepROQQAFCGZsHrZ+1w8IXcpoRJewDTXcAxVlkAI=; b=VF4v3uayc6+Js5MQsV3vKefbjbWWv2TuduKZsAk1EZk9Jz/2nzHdFmPlCItraqMWmRU90Q RAzFJlP0UB3/uy0OYPmrP0/3KiMGVeHROKEGC/vH3Qmqe6tHrucctRW9W+pSpvZ/cDfef4 DdXANNT9bSZExTiwJVx88p9rLnZyd9A= X-MC-Unique: 9-DKE8TIOPWZUcM3IXo91w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Lukas Straub Subject: [PULL 4/5] migration/ram.c: Fix migration with compress enabled Date: Wed, 12 Apr 2023 23:45:06 +0200 Message-Id: <20230412214507.19816-5-quintela@redhat.com> In-Reply-To: <20230412214507.19816-1-quintela@redhat.com> References: <20230412214507.19816-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -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_H2=-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: 1681335988775100003 Content-Type: text/plain; charset="utf-8" From: Lukas Straub Since ec6f3ab9, migration with compress enabled was broken, because the compress threads use a dummy QEMUFile which just acts as a buffer and that commit accidentally changed it to use the outgoing migration channel instead. Fix this by using the dummy file again in the compress threads. Signed-off-by: Lukas Straub Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 96e8a19a58..9d1817ab7b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -688,12 +688,11 @@ exit: * @offset: offset inside the block for the page * in the lower bits, it contains flags */ -static size_t save_page_header(PageSearchStatus *pss, RAMBlock *block, - ram_addr_t offset) +static size_t save_page_header(PageSearchStatus *pss, QEMUFile *f, + RAMBlock *block, ram_addr_t offset) { size_t size, len; bool same_block =3D (block =3D=3D pss->last_sent_block); - QEMUFile *f =3D pss->pss_channel; =20 if (same_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; @@ -867,7 +866,7 @@ static int save_xbzrle_page(RAMState *rs, PageSearchSta= tus *pss, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(pss, block, + bytes_xbzrle =3D save_page_header(pss, pss->pss_channel, block, offset | RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(file, ENCODING_FLAG_XBZRLE); qemu_put_be16(file, encoded_len); @@ -1302,15 +1301,14 @@ void ram_release_page(const char *rbname, uint64_t = offset) * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page_to_file(PageSearchStatus *pss, +static int save_zero_page_to_file(PageSearchStatus *pss, QEMUFile *file, RAMBlock *block, ram_addr_t offset) { uint8_t *p =3D block->host + offset; - QEMUFile *file =3D pss->pss_channel; int len =3D 0; =20 if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - len +=3D save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO); + len +=3D save_page_header(pss, file, block, offset | RAM_SAVE_FLAG= _ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(block->idstr, offset); @@ -1327,10 +1325,10 @@ static int save_zero_page_to_file(PageSearchStatus = *pss, * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, +static int save_zero_page(PageSearchStatus *pss, QEMUFile *f, RAMBlock *bl= ock, ram_addr_t offset) { - int len =3D save_zero_page_to_file(pss, block, offset); + int len =3D save_zero_page_to_file(pss, f, block, offset); =20 if (len) { stat64_add(&ram_atomic_counters.duplicate, 1); @@ -1394,7 +1392,7 @@ static int save_normal_page(PageSearchStatus *pss, RA= MBlock *block, { QEMUFile *file =3D pss->pss_channel; =20 - ram_transferred_add(save_page_header(pss, block, + ram_transferred_add(save_page_header(pss, pss->pss_channel, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, @@ -1473,11 +1471,11 @@ static bool do_compress_ram_page(QEMUFile *f, z_str= eam *stream, RAMBlock *block, uint8_t *p =3D block->host + offset; int ret; =20 - if (save_zero_page_to_file(pss, block, offset)) { + if (save_zero_page_to_file(pss, f, block, offset)) { return true; } =20 - save_page_header(pss, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + save_page_header(pss, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); =20 /* * copy it to a internal buffer to avoid it being modified by VM @@ -2355,7 +2353,7 @@ static int ram_save_target_page_legacy(RAMState *rs, = PageSearchStatus *pss) return 1; } =20 - res =3D save_zero_page(pss, block, offset); + res =3D save_zero_page(pss, pss->pss_channel, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale --=20 2.39.2 From nobody Fri May 17 06:07:56 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=1681336003; cv=none; d=zohomail.com; s=zohoarc; b=kFPiQNuzKW42WU7eQCs6BBjDAeYGDJ5tahLyuPdM7Kv2g4EvSjjKXfkDeCqWPCpvPcC0pKYDdPfQE/KNGzxPdKNsd+Letvm35DS9W5huPKPFjzxLU3s3iOMPCTyUTP8lscMb+//FXhQYL0wPMsE+JQaigwdHEegjE1LhQr8ZhrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681336003; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=BPBrb53DmJ8CjbFG14nTeT2QuDHlsQDJHH5J8fjC+I0=; b=UR4D6Ujzkq+Ic29JG/BB7JqTB/ArH4OmkRSOgVrpgSP0Iax4k3XiP94I4XGoxv5rCyBJ9BLl23pX5l4QfrStMj57n5zGRaoe+RWEvmZrSoiIavLuXVl2ee3uX75aK3pDvDuUGir4v9H9kMwRfieJpUJAjn4ppSRl167YWZqrU8w= 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 1681336003267823.0767734614932; Wed, 12 Apr 2023 14:46:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmiHN-0008NZ-H4; Wed, 12 Apr 2023 17:45:25 -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 1pmiHM-0008N0-Ez for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:24 -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 1pmiHK-0006dF-W7 for qemu-devel@nongnu.org; Wed, 12 Apr 2023 17:45:24 -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-484-O-ElFES6MF2eXAxLxbhFQA-1; Wed, 12 Apr 2023 17:45:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58A3A185A791; Wed, 12 Apr 2023 21:45:18 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D5451121320; Wed, 12 Apr 2023 21:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681335922; 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=BPBrb53DmJ8CjbFG14nTeT2QuDHlsQDJHH5J8fjC+I0=; b=LDSLdEXCTc1iPQbslbhinNBo4js9dZQf+B91cYjUiuGkjGNJ+ImZiC0Ko2TbUmsm57uPnP q/7zUoWmAxPGN86ZLUUAg97EqnTGClw2vYhOdk3r7MeGH9mt0Loh8YJtCGyM3UI4eGND+P wdBK81keF2jT6fzQ4OB+JcerPu9Vz/c= X-MC-Unique: O-ElFES6MF2eXAxLxbhFQA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Marcel Apfelbaum , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Yanan Wang , Juan Quintela , Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Nina Schoetterl-Glausch Subject: [PULL 5/5] migration: fix ram_state_pending_exact() Date: Wed, 12 Apr 2023 23:45:07 +0200 Message-Id: <20230412214507.19816-6-quintela@redhat.com> In-Reply-To: <20230412214507.19816-1-quintela@redhat.com> References: <20230412214507.19816-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -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_H2=-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: 1681336003826100001 Content-Type: text/plain; charset="utf-8" I removed that bit on commit: commit c8df4a7aeffcb46020f610526eea621fa5b0cd47 Author: Juan Quintela Date: Mon Oct 3 02:00:03 2022 +0200 migration: Split save_live_pending() into state_pending_* Fixes: c8df4a7aeffcb46020f610526eea621fa5b0cd47 Suggested-by: Nina Schoetterl-Glausch Signed-off-by: Juan Quintela --- migration/ram.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 9d1817ab7b..79d881f735 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3506,12 +3506,13 @@ static void ram_state_pending_estimate(void *opaque= , uint64_t *must_precopy, static void ram_state_pending_exact(void *opaque, uint64_t *must_precopy, uint64_t *can_postcopy) { + MigrationState *s =3D migrate_get_current(); RAMState **temp =3D opaque; RAMState *rs =3D *temp; =20 uint64_t remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SI= ZE; =20 - if (!migration_in_postcopy()) { + if (!migration_in_postcopy() && remaining_size < s->threshold_size) { qemu_mutex_lock_iothread(); WITH_RCU_READ_LOCK_GUARD() { migration_bitmap_sync_precopy(rs); --=20 2.39.2