From nobody Tue Nov 26 08:51:50 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=1709097574; cv=none; d=zohomail.com; s=zohoarc; b=KFhGw8+xtqDme0IkOSNjEEnKwlu+WSGgQw4Q4zZZ7NJrGVuy8+JCL+C4z4DitZoZNet9IYg02nmYBvw32ihhXt+D1+dKrIW5BvJNkoQkolG9BAuwzIkcr4AUCr9jEpBIe6R3ZX1ceXbFEDLWhlU5TthKL0AQHDsdOR7RVOpQxXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709097574; 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=LlFwz6O3mZ2LTaLrgZ+vg13FsQPgmVBoBxanF/BPCd4=; b=lqb1BV96AL/duVPi4dMt4pVjmmtBu80NTz8k6PB/i+rm2wL873uuP3fe4sb/hWVectKuuXbIBf2tjQLQp3sDOW7stnvZWk2ikNU/KstwBq3p19BfuRH8hg5aV73RpNNgTe8HfU/35sek3hgxILsM8PD5mPc1rvCAKBNbOIo3YOA= 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 1709097574931837.853127892893; Tue, 27 Feb 2024 21:19:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfCJx-0002Qc-DM; Wed, 28 Feb 2024 00:17:33 -0500 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 1rfCJK-0001Og-0W for qemu-devel@nongnu.org; Wed, 28 Feb 2024 00:17:02 -0500 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 1rfCJ5-0007Hu-Er for qemu-devel@nongnu.org; Wed, 28 Feb 2024 00:16:52 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-631-NuewWbeGNMimO56PS6ym3w-1; Wed, 28 Feb 2024 00:16:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 37A8438212C0; Wed, 28 Feb 2024 05:16:35 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 470661C060AF; Wed, 28 Feb 2024 05:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709097397; 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=LlFwz6O3mZ2LTaLrgZ+vg13FsQPgmVBoBxanF/BPCd4=; b=Bm9XiLx8L0JGpZASBUj3rhdY+3cmkqo0HECNHW38IxzzaNn1BoLfkLkDJFG7qpvnDXv1/m +yEXrrplMmmqPkSUlZELITBmZ6m0+Yui+XV074GvWiFXvTkUUu/8SEduNYasJjIFqCmXK9 w+P3VOxHgdCPlB4Ym+YnR++FhLTM23o= X-MC-Unique: NuewWbeGNMimO56PS6ym3w-1 From: peterx@redhat.com To: Peter Maydell , qemu-devel@nongnu.org Cc: David Hildenbrand , Eric Blake , Laurent Vivier , Paolo Bonzini , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Markus Armbruster , Fabiano Rosas , "Michael S. Tsirkin" , Thomas Huth , Jason Wang , Alex Williamson , Peter Xu , Steve Sistare Subject: [PULL 20/25] migration: stop vm for cpr Date: Wed, 28 Feb 2024 13:13:10 +0800 Message-ID: <20240228051315.400759-21-peterx@redhat.com> In-Reply-To: <20240228051315.400759-1-peterx@redhat.com> References: <20240228051315.400759-1-peterx@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=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.088, 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, 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: 1709097576186100008 Content-Type: text/plain; charset="utf-8" From: Steve Sistare When migration for cpr is initiated, stop the vm and set state RUN_STATE_FINISH_MIGRATE before ram is saved. This eliminates the possibility of ram and device state being out of sync, and guarantees that a guest in the suspended state remains suspended, because qmp_cont rejects a cont command in the RUN_STATE_FINISH_MIGRATE state. Signed-off-by: Steve Sistare Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/1708622920-68779-11-git-send-email-steven.s= istare@oracle.com Signed-off-by: Peter Xu --- include/migration/misc.h | 1 + migration/migration.h | 2 -- migration/migration.c | 51 ++++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index e4933b815b..5d1aa593ed 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -60,6 +60,7 @@ void migration_object_init(void); void migration_shutdown(void); bool migration_is_idle(void); bool migration_is_active(MigrationState *); +bool migrate_mode_is_cpr(MigrationState *); =20 typedef enum MigrationEventType { MIG_EVENT_PRECOPY_SETUP, diff --git a/migration/migration.h b/migration/migration.h index aef8afbe1f..65c0b61cbd 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -541,6 +541,4 @@ int migration_rp_wait(MigrationState *s); */ void migration_rp_kick(MigrationState *s); =20 -int migration_stop_vm(RunState state); - #endif diff --git a/migration/migration.c b/migration/migration.c index 37c836b0b0..90a90947fb 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -167,11 +167,19 @@ static gint page_request_addr_cmp(gconstpointer ap, g= constpointer bp) return (a > b) - (a < b); } =20 -int migration_stop_vm(RunState state) +static int migration_stop_vm(MigrationState *s, RunState state) { - int ret =3D vm_stop_force_state(state); + int ret; + + migration_downtime_start(s); + + s->vm_old_state =3D runstate_get(); + global_state_store(); + + ret =3D vm_stop_force_state(state); =20 trace_vmstate_downtime_checkpoint("src-vm-stopped"); + trace_migration_completion_vm_stop(ret); =20 return ret; } @@ -1602,6 +1610,11 @@ bool migration_is_active(MigrationState *s) s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE); } =20 +bool migrate_mode_is_cpr(MigrationState *s) +{ + return s->parameters.mode =3D=3D MIG_MODE_CPR_REBOOT; +} + int migrate_init(MigrationState *s, Error **errp) { int ret; @@ -2454,10 +2467,7 @@ static int postcopy_start(MigrationState *ms, Error = **errp) bql_lock(); trace_postcopy_start_set_run(); =20 - migration_downtime_start(ms); - - global_state_store(); - ret =3D migration_stop_vm(RUN_STATE_FINISH_MIGRATE); + ret =3D migration_stop_vm(ms, RUN_STATE_FINISH_MIGRATE); if (ret < 0) { goto fail; } @@ -2652,15 +2662,12 @@ static int migration_completion_precopy(MigrationSt= ate *s, int ret; =20 bql_lock(); - migration_downtime_start(s); - - s->vm_old_state =3D runstate_get(); - global_state_store(); =20 - ret =3D migration_stop_vm(RUN_STATE_FINISH_MIGRATE); - trace_migration_completion_vm_stop(ret); - if (ret < 0) { - goto out_unlock; + if (!migrate_mode_is_cpr(s)) { + ret =3D migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); + if (ret < 0) { + goto out_unlock; + } } =20 ret =3D migration_maybe_pause(s, current_active_state, @@ -3500,15 +3507,10 @@ static void *bg_migration_thread(void *opaque) s->setup_time =3D qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start; =20 trace_migration_thread_setup_complete(); - migration_downtime_start(s); =20 bql_lock(); =20 - s->vm_old_state =3D runstate_get(); - - global_state_store(); - /* Forcibly stop VM before saving state of vCPUs and devices */ - if (migration_stop_vm(RUN_STATE_PAUSED)) { + if (migration_stop_vm(s, RUN_STATE_PAUSED)) { goto fail; } /* @@ -3584,6 +3586,7 @@ void migrate_fd_connect(MigrationState *s, Error *err= or_in) Error *local_err =3D NULL; uint64_t rate_limit; bool resume =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_PAUSED; + int ret; =20 /* * If there's a previous error, free it and prepare for another one. @@ -3655,6 +3658,14 @@ void migrate_fd_connect(MigrationState *s, Error *er= ror_in) return; } =20 + if (migrate_mode_is_cpr(s)) { + ret =3D migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); + if (ret < 0) { + error_setg(&local_err, "migration_stop_vm failed, error %d", -= ret); + goto fail; + } + } + if (migrate_background_snapshot()) { qemu_thread_create(&s->thread, "bg_snapshot", bg_migration_thread, s, QEMU_THREAD_JOINABLE); --=20 2.43.0