From nobody Tue Nov 26 22:22:32 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=1704342801; cv=none; d=zohomail.com; s=zohoarc; b=D+LGUi5sdS3Da/cEJrtQyW4RI4RhmK1S735Mg0YyeZGkjUYrTkt8QM9odHtETsSj1XBQ30ZLc6ZGR0lXwGS1wDH7HZkTkrVX8rL6tqz3VzhgleQ9R6n+c2JgkWygzeTKEbhCWQ2ya/0HPFYYSTRdVTvVk/4GvAguOEWXQnsDyTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1704342801; 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=8TfpCka1YSMdMRbf5/huRwSV5G6ZPsE5XhlMly3s4AI=; b=nQqkExSxHZAautRmp/NBVMtaT+WG4Gtlaqomg6CFyW9BuVm1G/hcvjAQf+ydOrti5InYsyAhgoO/YGyXknYNI6sSotHSdaV71oVWCCPZmLeD37SbL+jijCyD2zXQQ38lA+SRdLvsy775kM+q4HPhQthk8O4El3VO457yTzi94yE= 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 1704342801501900.239830714916; Wed, 3 Jan 2024 20:33:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rLFPg-0000WE-Pd; Wed, 03 Jan 2024 23:33:00 -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 1rLFPf-0000Op-9p for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:32:59 -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 1rLFPd-0006ZZ-Bz for qemu-devel@nongnu.org; Wed, 03 Jan 2024 23:32:59 -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-389-28d9F-tAOKeKefhifK3dpg-1; Wed, 03 Jan 2024 23:32:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 109BF3816D84; Thu, 4 Jan 2024 04:32:55 +0000 (UTC) Received: from x1n.redhat.com (unknown [10.72.116.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39426C15968; Thu, 4 Jan 2024 04:32:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704342776; 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=8TfpCka1YSMdMRbf5/huRwSV5G6ZPsE5XhlMly3s4AI=; b=R3qdOUW9daCLalVkEYckRWh5h71OFZjZhbfNGPVg9O7546jhBi/FS57DM2tW087p+x5TRe tVA6IoUR3ORg5MtYKAlN1z3cRXSbvvbOT9VcN/ju/pVdELogxoriOSKlBrX5zxE9WqoE+P UQmwVUBT3v8ITdlrvUCSCWHeXvWHKuU= X-MC-Unique: 28d9F-tAOKeKefhifK3dpg-1 From: peterx@redhat.com To: qemu-devel@nongnu.org, Stefan Hajnoczi Cc: Fabiano Rosas , Steve Sistare , Juan Quintela , peterx@redhat.com, Leonardo Bras Soares Passos , Avihai Horon Subject: [PULL 07/26] migration: propagate suspended runstate Date: Thu, 4 Jan 2024 12:31:52 +0800 Message-ID: <20240104043213.431566-8-peterx@redhat.com> In-Reply-To: <20240104043213.431566-1-peterx@redhat.com> References: <20240104043213.431566-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -46 X-Spam_score: -4.7 X-Spam_bar: ---- X-Spam_report: (-4.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.601, 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, 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: 1704342803768100001 Content-Type: text/plain; charset="utf-8" From: Steve Sistare If the outgoing machine was previously suspended, propagate that to the incoming side via global_state, so a subsequent vm_start restores the suspended state. To maintain backward and forward compatibility, reclaim some space from the runstate member. Signed-off-by: Steve Sistare Reviewed-by: Peter Xu Link: https://lore.kernel.org/r/1704312341-66640-6-git-send-email-steven.si= stare@oracle.com Signed-off-by: Peter Xu --- migration/global_state.c | 47 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/migration/global_state.c b/migration/global_state.c index 4e2a9d8ec0..64a573c683 100644 --- a/migration/global_state.c +++ b/migration/global_state.c @@ -22,7 +22,16 @@ =20 typedef struct { uint32_t size; - uint8_t runstate[100]; + + /* + * runstate was 100 bytes, zero padded, but we trimmed it to add a + * few fields and maintain backwards compatibility. + */ + uint8_t runstate[32]; + uint8_t has_vm_was_suspended; + uint8_t vm_was_suspended; + uint8_t unused[66]; + RunState state; bool received; } GlobalState; @@ -35,6 +44,10 @@ static void global_state_do_store(RunState state) assert(strlen(state_str) < sizeof(global_state.runstate)); strpadcpy((char *)global_state.runstate, sizeof(global_state.runstate), state_str, '\0'); + global_state.has_vm_was_suspended =3D true; + global_state.vm_was_suspended =3D vm_get_suspended(); + + memset(global_state.unused, 0, sizeof(global_state.unused)); } =20 void global_state_store(void) @@ -59,24 +72,7 @@ RunState global_state_get_runstate(void) =20 static bool global_state_needed(void *opaque) { - GlobalState *s =3D opaque; - char *runstate =3D (char *)s->runstate; - - /* If it is not optional, it is mandatory */ - - if (migrate_get_current()->store_global_state) { - return true; - } - - /* If state is running or paused, it is not needed */ - - if (strcmp(runstate, "running") =3D=3D 0 || - strcmp(runstate, "paused") =3D=3D 0) { - return false; - } - - /* for any other state it is needed */ - return true; + return migrate_get_current()->store_global_state; } =20 static int global_state_post_load(void *opaque, int version_id) @@ -93,7 +89,7 @@ static int global_state_post_load(void *opaque, int versi= on_id) sizeof(s->runstate)) =3D=3D sizeof(s->runstate)) { /* * This condition should never happen during migration, because - * all runstate names are shorter than 100 bytes (the size of + * all runstate names are shorter than 32 bytes (the size of * s->runstate). However, a malicious stream could overflow * the qapi_enum_parse() call, so we force the last character * to a NUL byte. @@ -110,6 +106,14 @@ static int global_state_post_load(void *opaque, int ve= rsion_id) } s->state =3D r; =20 + /* + * global_state is saved on the outgoing side before forcing a stopped + * state, so it may have saved state=3Dsuspended and vm_was_suspended= =3D0. + * Now we are in a paused state, and when we later call vm_start, it m= ust + * restore the suspended state, so we must set vm_was_suspended=3D1 he= re. + */ + vm_set_suspended(s->vm_was_suspended || r =3D=3D RUN_STATE_SUSPENDED); + return 0; } =20 @@ -134,6 +138,9 @@ static const VMStateDescription vmstate_globalstate =3D= { .fields =3D (VMStateField[]) { VMSTATE_UINT32(size, GlobalState), VMSTATE_BUFFER(runstate, GlobalState), + VMSTATE_UINT8(has_vm_was_suspended, GlobalState), + VMSTATE_UINT8(vm_was_suspended, GlobalState), + VMSTATE_BUFFER(unused, GlobalState), VMSTATE_END_OF_LIST() }, }; --=20 2.41.0