From patchwork Tue Jan 14 23:07:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 231DBE77188 for ; Tue, 14 Jan 2025 23:09:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq0t-0001qC-W4; Tue, 14 Jan 2025 18:08: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 1tXq0r-0001nt-SR for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:07:57 -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 1tXq0p-00042q-MW for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:07:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896074; 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=uWccFfQ6jPbnEZLAIuZcotrIFjnbshq7v2GjTEBJen0=; b=BnF7f0HUAC07tAMHfOM8qZtD4b8/C5xn6szzxalfzPGVO3UlThg/TxwTzA2nVmQ2vFBgp9 DZJhgmV3zJJN/SCv25ETKImFYHsWv2ykcnn/yyuLkJle2OF2bVCOk021Xo/MVBhL17KLdA BVd3FXcyJQe0Pw4w29gN8YjdnSWpza4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-QkFucm6kMdmQ9rQi1HAf1A-1; Tue, 14 Jan 2025 18:07:53 -0500 X-MC-Unique: QkFucm6kMdmQ9rQi1HAf1A-1 X-Mimecast-MFC-AGG-ID: QkFucm6kMdmQ9rQi1HAf1A Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-467b19b5641so115641871cf.3 for ; Tue, 14 Jan 2025 15:07:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896072; x=1737500872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uWccFfQ6jPbnEZLAIuZcotrIFjnbshq7v2GjTEBJen0=; b=lKiMBoHlbXV1YfWb+bF6hkShj7UDhNOcu0YXFlAazdwvtXUes6daxPwTaN1TJS/iu9 Wzt/ZXpUJwy2p6ukqWxG6rat/xHz4IcqmKYhdhim19wWKTMf2yW108c920nToirR89DM MhpHzU9oGV2CfsLRyjA3n6YeTfZAEUVxGNJ0mxZ+Yi5L9prgIXDm9Z+BoZtwkwMn4Cb8 8VcGHr7E6Vd9FTlqklgzdTdH/nl+I1uv9EAKiEI3aom4YSgL0/kW30yCEWjZMHHO9wpq 2FUGZugbjlh1Xr2sEBM5ULLiA5FkFvdEEliB+LcAWjHoMy7GxmCLvT09cv6t2d9eIZh5 Ll+w== X-Gm-Message-State: AOJu0YyF3cewYixU8gWnRF3e/20ZHYI4F9/kJRNpjoqsmgnEzcCHcPSU he2OusrP9XnSKKhrau4Ht9yzfrUNFPxgnzv44CaQH7z7oufY5s0EOV9TxWSSE33r/pqBs/yBJkr tLjA9bvGQhmoNZ0LDOuxDbb6SKc69XzgcIbEOHpeBzyfrPY8q3mp6vcZQkxxeHqn0HLVcMgyHW+ OFBG9HvR1gkCZjOffpECyGXlJeIZzWUOkwJA== X-Gm-Gg: ASbGncuIWetLjSAn6vF2mc/WZw3eKXzoLdSnXQtIrViTofLVcayfuw7UnNDHBNZQypM OkC4qLP7YiTjYDYY1jyu3sx3OD/JhODpdzauvJZu0qDhn3FbOtk+tC9j1ZdzVMP5JPcre+KSLHx cnk8VV9xP0lCtMnI+tcDf2n28kRpbm+hNr9zdz7mXuP9fCDvnYD65I087nyA2+rFhORrt8DQLlV 6L5fqlHyBfx12qMVDnu2cmke/HTJLfRPSbPGHjcUzZmlPPLv5IIGrLjWmZ1NPO4caDRhhVZDayZ t9YQTsBqJQ60casTd+Zqmxe3PgLqLeIr X-Received: by 2002:a05:622a:449:b0:461:169e:d2dc with SMTP id d75a77b69052e-46c7108ecd7mr391061761cf.49.1736896072037; Tue, 14 Jan 2025 15:07:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFtojTRAhDGDSwPJY5iBDa/Arl4FWEjX74yDiW4aLs+kKISTglcPLKisCor3PpdhJeWqj0KIw== X-Received: by 2002:a05:622a:449:b0:461:169e:d2dc with SMTP id d75a77b69052e-46c7108ecd7mr391061461cf.49.1736896071669; Tue, 14 Jan 2025 15:07:51 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:50 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 01/16] migration: Remove postcopy implications in should_send_vmdesc() Date: Tue, 14 Jan 2025 18:07:31 -0500 Message-ID: <20250114230746.3268797-2-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org should_send_vmdesc() has a hack inside (which was not reflected in the function name) in that it tries to detect global postcopy state and that will affect the value to be returned. It's easier to keep the helper simple by only check the suppress-vmdesc property. Then: - On the sender side of its usage, there's already in_postcopy variable that we can use: postcopy doesn't send vmdesc at all, so directly skip everything for postcopy. - On the recv side, when reaching vmdesc processing it must be precopy code already, hence that hack check never used to work anyway. No functional change intended, except a trivial side effect that QEMU source will start to avoid running some JSON helper in postcopy path, but that would only reduce the postcopy blackout window a bit, rather than any other bad side effect. Signed-off-by: Peter Xu --- migration/savevm.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index c929da1ca5..0c4df27177 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1427,8 +1427,8 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy) static bool should_send_vmdesc(void) { MachineState *machine = MACHINE(qdev_get_machine()); - bool in_postcopy = migration_in_postcopy(); - return !machine->suppress_vmdesc && !in_postcopy; + + return !machine->suppress_vmdesc; } /* @@ -1563,16 +1563,16 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, if (!in_postcopy) { /* Postcopy stream will still be going */ qemu_put_byte(f, QEMU_VM_EOF); - } - json_writer_end_array(vmdesc); - json_writer_end_object(vmdesc); - vmdesc_len = strlen(json_writer_get(vmdesc)); + json_writer_end_array(vmdesc); + json_writer_end_object(vmdesc); + vmdesc_len = strlen(json_writer_get(vmdesc)); - if (should_send_vmdesc()) { - qemu_put_byte(f, QEMU_VM_VMDESCRIPTION); - qemu_put_be32(f, vmdesc_len); - qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); + if (should_send_vmdesc()) { + qemu_put_byte(f, QEMU_VM_VMDESCRIPTION); + qemu_put_be32(f, vmdesc_len); + qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); + } } /* Free it now to detect any inconsistencies. */ @@ -2965,6 +2965,7 @@ int qemu_loadvm_state(QEMUFile *f) return ret; } + /* When reaching here, it must be precopy */ if (ret == 0) { ret = qemu_file_get_error(f); } From patchwork Tue Jan 14 23:07:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 916F2E77188 for ; Tue, 14 Jan 2025 23:10:31 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq0v-0001qL-E1; Tue, 14 Jan 2025 18:08:01 -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 1tXq0t-0001q2-J5 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:07: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 1tXq0r-00042y-NI for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:07:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896076; 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=HJR38tp/bNFIvxL2s+ykIG6k6iWIvuZ+RXhgC0s5ndE=; b=ZgJXQ5mLapWMe4ZmL7yltSBeZJoY7SUPTbfZm1+0FhTsWp8ymU+KIBKYjawrEujkQHropL 259Cl51QY6HkpZhv0D0uRdeXw6UKqSGDloc5+1V4P4hJhKd9bKu39A+OtgYOpd7DiQoCpp n9OZ6fEDIB1RBYTz/bN+91r23GMiPkw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-385-G8Nm5LH-Nw22VLT2Wa6EPA-1; Tue, 14 Jan 2025 18:07:54 -0500 X-MC-Unique: G8Nm5LH-Nw22VLT2Wa6EPA-1 X-Mimecast-MFC-AGG-ID: G8Nm5LH-Nw22VLT2Wa6EPA Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6d8844560e9so127907766d6.3 for ; Tue, 14 Jan 2025 15:07:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896074; x=1737500874; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HJR38tp/bNFIvxL2s+ykIG6k6iWIvuZ+RXhgC0s5ndE=; b=sS9gQ357FjsAGxlB34T1D/tzMsXp2llXxiT+EnHHfEoTlPVg4FSxm8KYbiuWjVAiNc xh5oKaGOXLm/R3A/rTk3CvFp//5C3pvFNua7QEdAV9c4C/Q1bFPkgoCDGhIf3QRlHluB CUUQjLR789khEedmInInesyUQp1utArzJpGT08YnhtFF/Ei2xQ380hyG4FLO2iGMOS4j lpZv8lbM0Erj1xp5h+H8X0e0Ou24ep8g+ji4vSyvXGFxDoR/AztgudPUVhTWB0M1mHU+ Q7JtlJ6X1VMvdqK2DK1L8k7mlVTq8ZAIGO5jbvQcp4Y+lhd0vxCDiI0XLm5KhFO214m1 2wsg== X-Gm-Message-State: AOJu0Yx3aPKvWAqq8dlmHSPvBvGHoOc7tJIkUsYM22UxOYTRLpFBQY2d qclDXUZWg2KjMC+0HKnua4SNesE/rcuzVT9igKd8PDkZFvm0ZdC0onn+ssO0Nqih0t8jRmmXUuA 8ueGle/yprxPYzQa3t4Rg369Qf/WjfePBNmdPUNxrXG19DbGxfNJlQzlMWl2G+GP6B/T4r0UqUS rlscz30AlX0vaRs0/GAX4/87Sv+jXe3ray9Q== X-Gm-Gg: ASbGncufJJCPetlEKj5vqDePLYgV+dhyH1gFORKTrUVO7P/0hK6y6dqaRuS16g1RV7L 1gWNpUxt+kLUBGhS7eL7Q1HSwfcySfm74utKMemJPCAif7tjpvjk1WZ9TtF1etj8dDVXq5zx71U W808FcIJMV89N+4YRgCTz6GOoqdTbQIDHfiVWYar39ag/pmj8dkCtlPYc0EZIdH/np9lJD7wL57 RYEbXEQt1QPk9SBTqD6Awb7fljrOODybM+nORg+Kc9b51TrU6NG2b1Anz3YGOHEQd0HGVYQqc1L xdcDMHfHtb7I60ILlvY+gn12H0bAF3q6 X-Received: by 2002:a05:6214:2428:b0:6d8:960e:5785 with SMTP id 6a1803df08f44-6df9b234c28mr397065786d6.13.1736896073687; Tue, 14 Jan 2025 15:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaVQ7cUOeZkDKamGe9n5EjP7CAWu9sKmnkY9zIoiZHSSm+3xLHZ2dJ0n69d4q+NC6zSyOAtg== X-Received: by 2002:a05:6214:2428:b0:6d8:960e:5785 with SMTP id 6a1803df08f44-6df9b234c28mr397065356d6.13.1736896073195; Tue, 14 Jan 2025 15:07:53 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:52 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 02/16] migration: Do not construct JSON description if suppressed Date: Tue, 14 Jan 2025 18:07:32 -0500 Message-ID: <20250114230746.3268797-3-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org QEMU machine has a property "suppress-vmdesc". When it is enabled, QEMU will stop attaching JSON VM description at the end of the precopy migration stream (postcopy is never affected because postcopy never attach that). However even if it's suppressed by the user, the source QEMU will still construct the JSON descriptions, which is a complete waste of CPU and memory resources. To avoid it, only create the JSON writer object if suppress-vmdesc is not specified. Luckily, vmstate_save() already supports vmdesc==NULL, so only a few spots that are left to be prepared that vmdesc can be NULL now. When at it, move the init / destroy of the JSON writer object to start / end of the migration - the JSON writer object is a sub-struct of migration state, and that looks like the only object that was dynamically allocated / destroyed within migration process. Make it the same as the rest objects that migration uses. Signed-off-by: Peter Xu --- migration/migration.h | 1 + migration/migration.c | 9 +++++--- migration/savevm.c | 49 +++++++++++++++++++++++-------------------- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index 0df2a187af..3f1927f79c 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -552,6 +552,7 @@ void migration_bitmap_sync_precopy(bool last_stage); /* migration/block-dirty-bitmap.c */ void dirty_bitmap_mig_init(void); +bool should_send_vmdesc(void); /* migration/block-active.c */ void migration_block_active_setup(bool active); diff --git a/migration/migration.c b/migration/migration.c index 2d1da917c7..bad7b39293 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1406,8 +1406,8 @@ static void migrate_fd_cleanup(MigrationState *s) g_free(s->hostname); s->hostname = NULL; - json_writer_free(s->vmdesc); - s->vmdesc = NULL; + + g_clear_pointer(&s->vmdesc, json_writer_free); qemu_savevm_state_cleanup(); @@ -1681,7 +1681,10 @@ int migrate_init(MigrationState *s, Error **errp) s->migration_thread_running = false; error_free(s->error); s->error = NULL; - s->vmdesc = NULL; + + if (should_send_vmdesc()) { + s->vmdesc = json_writer_new(false); + } migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP); diff --git a/migration/savevm.c b/migration/savevm.c index 0c4df27177..fa03a0a264 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1231,8 +1231,7 @@ void qemu_savevm_non_migratable_list(strList **reasons) void qemu_savevm_state_header(QEMUFile *f) { MigrationState *s = migrate_get_current(); - - s->vmdesc = json_writer_new(false); + JSONWriter *vmdesc = s->vmdesc; trace_savevm_state_header(); qemu_put_be32(f, QEMU_VM_FILE_MAGIC); @@ -1241,16 +1240,21 @@ void qemu_savevm_state_header(QEMUFile *f) if (s->send_configuration) { qemu_put_byte(f, QEMU_VM_CONFIGURATION); - /* - * This starts the main json object and is paired with the - * json_writer_end_object in - * qemu_savevm_state_complete_precopy_non_iterable - */ - json_writer_start_object(s->vmdesc, NULL); + if (vmdesc) { + /* + * This starts the main json object and is paired with the + * json_writer_end_object in + * qemu_savevm_state_complete_precopy_non_iterable + */ + json_writer_start_object(vmdesc, NULL); + json_writer_start_object(vmdesc, "configuration"); + } + + vmstate_save_state(f, &vmstate_configuration, &savevm_state, vmdesc); - json_writer_start_object(s->vmdesc, "configuration"); - vmstate_save_state(f, &vmstate_configuration, &savevm_state, s->vmdesc); - json_writer_end_object(s->vmdesc); + if (vmdesc) { + json_writer_end_object(vmdesc); + } } } @@ -1296,16 +1300,19 @@ int qemu_savevm_state_setup(QEMUFile *f, Error **errp) { ERRP_GUARD(); MigrationState *ms = migrate_get_current(); + JSONWriter *vmdesc = ms->vmdesc; SaveStateEntry *se; int ret = 0; - json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size()); - json_writer_start_array(ms->vmdesc, "devices"); + if (vmdesc) { + json_writer_int64(vmdesc, "page_size", qemu_target_page_size()); + json_writer_start_array(vmdesc, "devices"); + } trace_savevm_state_setup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (se->vmsd && se->vmsd->early_setup) { - ret = vmstate_save(f, se, ms->vmdesc, errp); + ret = vmstate_save(f, se, vmdesc, errp); if (ret) { migrate_set_error(ms, *errp); qemu_file_set_error(f, ret); @@ -1424,7 +1431,7 @@ int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy) return all_finished; } -static bool should_send_vmdesc(void) +bool should_send_vmdesc(void) { MachineState *machine = MACHINE(qdev_get_machine()); @@ -1564,21 +1571,17 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, /* Postcopy stream will still be going */ qemu_put_byte(f, QEMU_VM_EOF); - json_writer_end_array(vmdesc); - json_writer_end_object(vmdesc); - vmdesc_len = strlen(json_writer_get(vmdesc)); + if (vmdesc) { + json_writer_end_array(vmdesc); + json_writer_end_object(vmdesc); + vmdesc_len = strlen(json_writer_get(vmdesc)); - if (should_send_vmdesc()) { qemu_put_byte(f, QEMU_VM_VMDESCRIPTION); qemu_put_be32(f, vmdesc_len); qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); } } - /* Free it now to detect any inconsistencies. */ - json_writer_free(vmdesc); - ms->vmdesc = NULL; - trace_vmstate_downtime_checkpoint("src-non-iterable-saved"); return 0; From patchwork Tue Jan 14 23:07:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 20A4FC02187 for ; Tue, 14 Jan 2025 23:08:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq0x-0001rI-Ks; Tue, 14 Jan 2025 18:08:03 -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 1tXq0w-0001qo-2K for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08: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 1tXq0u-00043U-J0 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896079; 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=enSH5rlxcTb/KVObjDkc8rdqQsMxW2lwvt88NiL40BA=; b=GAcoavBNhXWu+QhAEk3OA8U+KU0Oil0CyIkPDkmXnM2jfneo3n51NKsUc0RAGXNly17ZBb lH3JjyBSrC2WK+RfzcBXGiukww90hyl5j2Sb0M9xF3tH6I00xIvBVcy+NdqAAh2gX3/QFw wUPiB+nw40h4S6nfRCCizAEfeTQgsHs= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-mSHRlySrNpWY4uCGChMGjQ-1; Tue, 14 Jan 2025 18:07:56 -0500 X-MC-Unique: mSHRlySrNpWY4uCGChMGjQ-1 X-Mimecast-MFC-AGG-ID: mSHRlySrNpWY4uCGChMGjQ Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-46c83bc370bso5734481cf.0 for ; Tue, 14 Jan 2025 15:07:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896075; x=1737500875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=enSH5rlxcTb/KVObjDkc8rdqQsMxW2lwvt88NiL40BA=; b=eJ4hrB0mkkSvDiNr9PeOTxN/sgDZ5UZLFH0bGZV5c3uBDvg4NY0zrgnnD0RYAlPvxB S6wFILW9ICaraf0AOByTVZxP2VdzLjnWKmt6N8NxyP9Zt6G+pPuyQwENorqQLxy8JArb 9dbyrNpGU8iiJafISRNw4GcPvWHk8/UBnTvHeu2d3aKrblzkFQ1n/27qqtZ9P7IsdTMi 2TZuJTW7X3y2+3K0PcAFh1G19fdqI6/wp53xqMMhRLu0JToM1yXl5Z44rnFuJsB+0nGh VrFh86+PWc8BTreeVZgIKLZAQBwmrMAI+JCpPWC0GDaNTVEU6YccwKLOEOFPnGp5FPWM Inxg== X-Gm-Message-State: AOJu0YwW04rEHCpyz1Q3zTq3bDGC0RP9ITI5T963OG+vN27kAiYI1GXb JHHj99Nc5NLfJ8bTa5JatCb4JLrPzT8HI1iYSBjzEPYO3VReHklP6DT2WdzSygri55JpGMaEUyz 9RGf82Tpn+gmKgB1L2bduxq5cmtUXGkldjt5Ve6lFICY0bC6ckJRkkwD8LbRMe26x0lNaEC7V84 3ATE9Af2QXQs2zcO0AmIc2+TnRF+bhNqkFcg== X-Gm-Gg: ASbGncuk/2NyA6xZ7V9jc8d7XgO/rypddPq1mu/d3KjeRqo2G+mCpsiaf3gqsJP00x0 BR8YLv8FklZCg7GSIQxRkPT23PvGFy4Xw9jrrFtzYjXdsu6OWb15zcMJBdOWDkVQwzEMdKCdlKz Gp3+IysS+/FsZrnm/eA3bTh8q5lM5ILgbErsCvdAOrbnWlwHF0HOAHx/a/kifKRc/X/rFJfbeh1 5boaMODwHt8z3MvUjdsmlMH91sR6Oz1vjxyhIoTBVHXo/C+2FfyvUqXZJeR2uH6Chkpy0zPf8tn TuUv+YAdYsuX6tsHdiw4221/3UQMBPl9 X-Received: by 2002:a05:622a:5a07:b0:467:85f9:2a6c with SMTP id d75a77b69052e-46df569e6f0mr14053131cf.10.1736896074904; Tue, 14 Jan 2025 15:07:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6CnqlXk+V6YEg6yK9um5/g0qtpiIkDWbqOmkTL2DWXP+7th4OYi4UEewIWCI4VCGYIcO3MQ== X-Received: by 2002:a05:622a:5a07:b0:467:85f9:2a6c with SMTP id d75a77b69052e-46df569e6f0mr14052811cf.10.1736896074572; Tue, 14 Jan 2025 15:07:54 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:53 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 03/16] migration: Optimize postcopy on downtime by avoiding JSON writer Date: Tue, 14 Jan 2025 18:07:33 -0500 Message-ID: <20250114230746.3268797-4-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org postcopy_start() is the entry function that postcopy is destined to start. It also means QEMU source will not dump VM description, aka, the JSON writer is garbage now. We can leave that to be cleaned up when migration completes, however when with the JSON writer object being present, vmstate_save() will still try to construct the JSON objects for the VM descriptions, even though it'll never be used later if it's postcopy. To save those cycles, release the JSON writer earlier for postcopy. Then vmstate_save() later will be smart enough to skip the JSON object constructions completely. It can logically reduce downtime because all such JSON constructions happen during postcopy blackout. Signed-off-by: Peter Xu --- migration/migration.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index bad7b39293..0eb28e850d 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1397,6 +1397,11 @@ void migrate_set_state(MigrationStatus *state, MigrationStatus old_state, } } +static void migration_cleanup_json_writer(MigrationState *s) +{ + g_clear_pointer(&s->vmdesc, json_writer_free); +} + static void migrate_fd_cleanup(MigrationState *s) { MigrationEventType type; @@ -1404,11 +1409,11 @@ static void migrate_fd_cleanup(MigrationState *s) trace_migrate_fd_cleanup(); + migration_cleanup_json_writer(s); + g_free(s->hostname); s->hostname = NULL; - g_clear_pointer(&s->vmdesc, json_writer_free); - qemu_savevm_state_cleanup(); close_return_path_on_source(s); @@ -2501,6 +2506,14 @@ static int postcopy_start(MigrationState *ms, Error **errp) uint64_t bandwidth = migrate_max_postcopy_bandwidth(); int cur_state = MIGRATION_STATUS_ACTIVE; + /* + * Now we're 100% sure to switch to postcopy, so JSON writer won't be + * useful anymore. Free the resources early if it is there. Clearing + * the vmdesc also means any follow up vmstate_save()s will start to + * skip all JSON operations, which can shrink postcopy downtime. + */ + migration_cleanup_json_writer(ms); + if (migrate_postcopy_preempt()) { migration_wait_main_channel(ms); if (postcopy_preempt_establish_channel(ms)) { From patchwork Tue Jan 14 23:07:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939636 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5A8A6E77188 for ; Tue, 14 Jan 2025 23:08:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq0y-0001rM-1F; Tue, 14 Jan 2025 18:08:04 -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 1tXq0v-0001qZ-SW for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:01 -0500 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 1tXq0u-00043H-0u for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896078; 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=3J/rPBYuBb2FewjBzx58s7MHMBJWtOIl+Z3hEAriHYI=; b=WyEuC454pPO/PL6UA+5E+RblCoSSPUv5pfCHoZReq02+iTBs8getnt6M43KG8ELKa6jJca hqYR6Bz89bHK6dsD0uTkiRJmQEkha8QSdso950IC+Z6+MyMfMtev1JGn0+8KpFtE1civii ryeRa8B+HZW78GGOoYcji0X8gJiuwiI= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-eUUhcY8MPDWjG5gB5KlaCg-1; Tue, 14 Jan 2025 18:07:57 -0500 X-MC-Unique: eUUhcY8MPDWjG5gB5KlaCg-1 X-Mimecast-MFC-AGG-ID: eUUhcY8MPDWjG5gB5KlaCg Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6d8edb40083so5804186d6.0 for ; Tue, 14 Jan 2025 15:07:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896076; x=1737500876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3J/rPBYuBb2FewjBzx58s7MHMBJWtOIl+Z3hEAriHYI=; b=ZKe8CgPIpCDXz/WWomYS+e05iBuZlRygSowK7ldum3cNEh8xdiyYXhLilQdhJauEWQ HN3dG7mjZDq+m1NECwfLhw2qaSY/3L4cyE5PjlvrDRWAin+pKWRVAFE2bh2/9O9hKaf6 nge2Fy6ccj2e6HCu0AB0Pikf+x9a4POvmb+Bzi3gpLhAyenuLL261aVMLw2nBFbb2ODd D2CYHk2DYXiBNWtDUC6Uud/pB3sZjMV1dERd8dLb5bx2BBMZ8nBCJZMODmS24hVy+8ZR G7Auopr/kUgUWZWoZ6xGO2ZJ+BEKLEWD9zCcD1ZoAugJOiAEZWk1KCDkBJwrTmksaYbS zniA== X-Gm-Message-State: AOJu0YzjNVHTlnWJjfl5dGbRDStCkwZURFtdwbgWKjjOlkUnyZ8euD9g 18uvSJuLmE2zJI0EDPS/EZ+cd0VdKMdk5ORgIQwL+q3XmUHEJT1pqfmbYnFisp9v4ifLD6mdt9o 0UP8LV6eEnGbJg2qyZxaMNHsHvuQnxyQg7A4OuDV32b1z3/htNkfmQgXrlU/UmAhZAb7VRc7Jdz kqMwyh+db6S6E5ukF5+OuAwT/Q+b/erbw34g== X-Gm-Gg: ASbGncvGKoax2pKb24i5QWtavb2LZkVzx39D+9JfTJmpbdoxRzdT+VmGEjwk653mre1 hKeMX/p28IiNWbDdyHZOvOymYnrgMl6MvBtfOhk1NULDV9LkJyqU7gdk/OBcO4E2fpx6bFSTxy4 c91ksQRmejMuzabwoEkXW/2igioHDwnZF11sB/6ioroXk1KH9iJRJmgoFWGdQdb2nlvKuN9o9Ds dp9UeuuDlYPjA/J2ai0etepIygA3CYiwEpsrjRM9oKG0q/Lvh/uDOuPMfqtGIcqaA5tpm+1RaoD GLNsoDMNUAkX9h6tWfNE8p2tKZ/jKTN+ X-Received: by 2002:a05:6214:4304:b0:6d8:94f4:d2aa with SMTP id 6a1803df08f44-6e192ba8f77mr13300656d6.13.1736896076597; Tue, 14 Jan 2025 15:07:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA1j1uzcCfD952uDr001iSj5ctgQyLTwui95k2K9oiuvWnqScV+0HA6nI8eJD/RzYSP7FyHw== X-Received: by 2002:a05:6214:4304:b0:6d8:94f4:d2aa with SMTP id 6a1803df08f44-6e192ba8f77mr13300426d6.13.1736896076320; Tue, 14 Jan 2025 15:07:56 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:55 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 04/16] migration: Avoid two src-downtime-end tracepoints for postcopy Date: Tue, 14 Jan 2025 18:07:34 -0500 Message-ID: <20250114230746.3268797-5-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Postcopy can trigger this tracepoint twice, while only the 1st one is valid. Avoid triggering the 2nd tracepoint just like what we do with recording the total downtime. Signed-off-by: Peter Xu --- migration/migration.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 0eb28e850d..e1fc1a7fdc 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -125,9 +125,8 @@ static void migration_downtime_end(MigrationState *s) */ if (!s->downtime) { s->downtime = now - s->downtime_start; + trace_vmstate_downtime_checkpoint("src-downtime-end"); } - - trace_vmstate_downtime_checkpoint("src-downtime-end"); } static bool migration_needs_multiple_sockets(void) From patchwork Tue Jan 14 23:07:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 95720C02185 for ; Tue, 14 Jan 2025 23:08:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq11-0001t4-O0; Tue, 14 Jan 2025 18:08:07 -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 1tXq0z-0001rd-G7 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:05 -0500 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 1tXq0x-00043a-Gh for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896080; 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=puz3fqWAe4p+E3jR68kieXjasW6yV218uFcwIMo6OkE=; b=eQ2wJ/9MrQddeV6gxPr+Atlj8ykMEtrawifWrUZE2kwseTh5j1S8Fw99Yo4cSgQ26aMSwa s6vPdhHF4JtyANubS3plmM6AHOX3mh6jSaz5LPd6rE6b/SFQwNDLGQ7zAfSArhzf6wTPW1 ERofEiQa/G3Tj2TsFj2Ve1Oxim39rEw= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-J2m4sK_mM0eqk_Vsx_8sWw-1; Tue, 14 Jan 2025 18:07:59 -0500 X-MC-Unique: J2m4sK_mM0eqk_Vsx_8sWw-1 X-Mimecast-MFC-AGG-ID: J2m4sK_mM0eqk_Vsx_8sWw Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-467944446a0so92870271cf.1 for ; Tue, 14 Jan 2025 15:07:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896078; x=1737500878; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=puz3fqWAe4p+E3jR68kieXjasW6yV218uFcwIMo6OkE=; b=pLQzxHDmEVGaF6SZVwe4jsnJVmaMZOlE7kUHBQv7uSx76SCwOp85Jl7nqNiafIaTpo haUVOMMXAfU1Kn2urwHwqfk40hnWImpYcA7nji1m+9YT2a+SNzip8maWAzexJPaQaq+t MiS/dFmgcPJtLxSSQMxHZIfsqniK8bPbnmOGDX46JlrHcXJbLOE/LfOexUE+Muo3UK/c uzpkRu3ZVjNiByTgsY/0NcGbOVu/DvP2HwZ/gDhuli67qiKLtT73KgBjpz0zQlMbICFR PPea5uObeWDEA1fZKoveuPg2qJl4HuHjs/UchOuvxVoPoEior/xiQSpMCv9HC5sv88df U4kQ== X-Gm-Message-State: AOJu0YzbFJnYIQelGVHcNcp/ga/nRhCBlZSBxNGl+5wqoS6WJDY2k5cW FljsDN/1unMnwjTeB/MvwXx/kceVXpjBiyIeNeUYe6OjoCMyswjhEJCp+F610p5Qebrd3di/Z0O qouoYmnZxPm0TEDuBJDiqiVt5y9mazF1wpPEorEiTLsP73iZcsuFd11uKidh+7rL5yEk+IautjD HTeFFodzEwnukscGrxUO7ISRz5lPHmAlcOww== X-Gm-Gg: ASbGncu8SnEPh2aNgocInFShhSy9RLjGcDKouiDMcTggFu778weqH2J9FEOLfWnMsYn yn/VRs8336z6ZAomrK2jKOgTm0IwvRDkqoTYWarWliHM8Xl3I4yaIvGz8of8lxLsrpNxAPgiFT3 Fcj3T8+4Kz630WF8J3EA/5jfT9p1mIzU3QqWBm2CBTqeg0BB/VoEGhnYPwDJR+GZhFBnJe9HRFN itD/IiS0LhQj4v87qWR3xfLwBEizWmpHJTGYEL6V+f7/v/zMwMu2QYUmWl2fS86CXzx68kuEB5N Y6+VJSRoQdTnTBOsOxIyJ9Fn/NRcakRp X-Received: by 2002:a05:622a:1996:b0:466:a584:69f8 with SMTP id d75a77b69052e-46c7107a481mr493237521cf.43.1736896078530; Tue, 14 Jan 2025 15:07:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEOwXKNfSOlRCWj63VkMLObuQvi3Q1tq3vDHbie9CN+gMnTFWWVeEm4PpO6yurFvUKHIX4VKA== X-Received: by 2002:a05:622a:1996:b0:466:a584:69f8 with SMTP id d75a77b69052e-46c7107a481mr493237081cf.43.1736896078088; Tue, 14 Jan 2025 15:07:58 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:57 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 05/16] migration: Drop inactivate_disk param in qemu_savevm_state_complete* Date: Tue, 14 Jan 2025 18:07:35 -0500 Message-ID: <20250114230746.3268797-6-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This parameter is only used by one caller, which is the genuine precopy complete path (migration_completion_precopy). The parameter was introduced in a1fbe750fd ("migration: Fix race of image locking between src and dst") to make sure the inactivate will happen before EOF to make sure dest will always be able to activate the disk properly. However there's no limitation on how early we inactivate the disk. For precopy completion path, we can always do that as long as VM is stopped. Move the disk inactivate there, then we can remove this inactivate_disk parameter in the whole call stack, because all the rest users pass in false always. Signed-off-by: Peter Xu --- migration/savevm.h | 5 ++--- migration/migration.c | 22 ++++++++++++++++------ migration/savevm.c | 27 +++++---------------------- 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/migration/savevm.h b/migration/savevm.h index 9ec96a995c..c48a53e95e 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -39,8 +39,7 @@ void qemu_savevm_state_header(QEMUFile *f); int qemu_savevm_state_iterate(QEMUFile *f, bool postcopy); void qemu_savevm_state_cleanup(void); void qemu_savevm_state_complete_postcopy(QEMUFile *f); -int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, - bool inactivate_disks); +int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only); void qemu_savevm_state_pending_exact(uint64_t *must_precopy, uint64_t *can_postcopy); void qemu_savevm_state_pending_estimate(uint64_t *must_precopy, @@ -68,6 +67,6 @@ int qemu_loadvm_state_main(QEMUFile *f, MigrationIncomingState *mis); int qemu_load_device_state(QEMUFile *f); int qemu_loadvm_approve_switchover(void); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, - bool in_postcopy, bool inactivate_disks); + bool in_postcopy); #endif diff --git a/migration/migration.c b/migration/migration.c index e1fc1a7fdc..b33baab950 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2555,7 +2555,7 @@ static int postcopy_start(MigrationState *ms, Error **errp) * Cause any non-postcopiable, but iterative devices to * send out their final data. */ - qemu_savevm_state_complete_precopy(ms->to_dst_file, true, false); + qemu_savevm_state_complete_precopy(ms->to_dst_file, true); /* * in Finish migrate and with the io-lock held everything should @@ -2600,7 +2600,7 @@ static int postcopy_start(MigrationState *ms, Error **errp) */ qemu_savevm_send_postcopy_listen(fb); - qemu_savevm_state_complete_precopy(fb, false, false); + qemu_savevm_state_complete_precopy(fb, false); if (migrate_postcopy_ram()) { qemu_savevm_send_ping(fb, 3); } @@ -2732,11 +2732,21 @@ static int migration_completion_precopy(MigrationState *s, goto out_unlock; } + /* Inactivate disks except in COLO */ + if (!migrate_colo()) { + /* + * Inactivate before sending QEMU_VM_EOF so that the + * bdrv_activate_all() on the other end won't fail. + */ + if (!migration_block_inactivate()) { + ret = -EFAULT; + goto out_unlock; + } + } + migration_rate_set(RATE_LIMIT_DISABLED); - /* Inactivate disks except in COLO */ - ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false, - !migrate_colo()); + ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false); out_unlock: bql_unlock(); return ret; @@ -3617,7 +3627,7 @@ static void *bg_migration_thread(void *opaque) * save their state to channel-buffer along with devices. */ cpu_synchronize_all_states(); - if (qemu_savevm_state_complete_precopy_non_iterable(fb, false, false)) { + if (qemu_savevm_state_complete_precopy_non_iterable(fb, false)) { goto fail; } /* diff --git a/migration/savevm.c b/migration/savevm.c index fa03a0a264..5e56a5d9fc 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1521,8 +1521,7 @@ int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy) } int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, - bool in_postcopy, - bool inactivate_disks) + bool in_postcopy) { MigrationState *ms = migrate_get_current(); int64_t start_ts_each, end_ts_each; @@ -1553,20 +1552,6 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, end_ts_each - start_ts_each); } - if (inactivate_disks) { - /* - * Inactivate before sending QEMU_VM_EOF so that the - * bdrv_activate_all() on the other end won't fail. - */ - if (!migration_block_inactivate()) { - error_setg(&local_err, "%s: bdrv_inactivate_all() failed", - __func__); - migrate_set_error(ms, local_err); - error_report_err(local_err); - qemu_file_set_error(f, -EFAULT); - return ret; - } - } if (!in_postcopy) { /* Postcopy stream will still be going */ qemu_put_byte(f, QEMU_VM_EOF); @@ -1587,8 +1572,7 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, return 0; } -int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, - bool inactivate_disks) +int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only) { int ret; Error *local_err = NULL; @@ -1613,8 +1597,7 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, goto flush; } - ret = qemu_savevm_state_complete_precopy_non_iterable(f, in_postcopy, - inactivate_disks); + ret = qemu_savevm_state_complete_precopy_non_iterable(f, in_postcopy); if (ret) { return ret; } @@ -1717,7 +1700,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp) ret = qemu_file_get_error(f); if (ret == 0) { - qemu_savevm_state_complete_precopy(f, false, false); + qemu_savevm_state_complete_precopy(f, false); ret = qemu_file_get_error(f); } if (ret != 0) { @@ -1743,7 +1726,7 @@ cleanup: void qemu_savevm_live_state(QEMUFile *f) { /* save QEMU_VM_SECTION_END section */ - qemu_savevm_state_complete_precopy(f, true, false); + qemu_savevm_state_complete_precopy(f, true); qemu_put_byte(f, QEMU_VM_EOF); } From patchwork Tue Jan 14 23:07:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3ED85C02183 for ; Tue, 14 Jan 2025 23:09:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq11-0001t7-PE; Tue, 14 Jan 2025 18:08:07 -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 1tXq10-0001rv-7l for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:06 -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 1tXq0y-00043u-J6 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896084; 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=ZE4uhT0efoyzNOkHySdc0SxAsnss5S/fqug5y/Yd9+M=; b=Cc1sWjb/Y32Xo2TB+lbnPQ4lsnacyBUFlRcVLAXm3rVdqsXyjcH/aims3jjAdpyyGuJCHK ElR/5uuPjCg0rsBdrVq5k/EctyIdwdMohb53B3c5VOrqOxdc8u34Fb4N2p5UQaOnP0BP8k 0+SNtzICeMP4RgReFINgQFfRogfUpts= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-259-1hkkFWGcPoyf7kr4d-McAA-1; Tue, 14 Jan 2025 18:08:01 -0500 X-MC-Unique: 1hkkFWGcPoyf7kr4d-McAA-1 X-Mimecast-MFC-AGG-ID: 1hkkFWGcPoyf7kr4d-McAA Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6d88d56beb7so58884066d6.3 for ; Tue, 14 Jan 2025 15:08:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896080; x=1737500880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZE4uhT0efoyzNOkHySdc0SxAsnss5S/fqug5y/Yd9+M=; b=X3+v0YwWirFWjJYYw35KmrFkD5Kfg3Qys39qOKFD69nvnoP6Tzw1IsqW6HuInknuRQ OVWqJQM6roL+6paI1AcSKw53/u53lSEDJx1tGWNHQ/wuVOXPpM5AmG6PniIPiJ6Ei9ez WGuZwR5jLSSqKVSyZFpdddYFzQj5SNbGSv8Q3vcBAw4wZyomqgakchtKV9shc3mQ1QVq 00uIMhHC3yytZExSCxYblUOh6w26RqGx68FrHGfTL6twqeRMohqwEBZVVTl0bpgIRq9k qYp292LaPgkFd4gdNpsCbR9KyrwVfqCkfGR4kUhlUaUAKrHVKJE/oJntbjDpiXbm2ZS+ 9f2g== X-Gm-Message-State: AOJu0YwSoiTzgIuUQPDYMN8bKdvZZq3xzTcee8MaKaz4Ssjs/NXgR4dd ay9MLxuXfjamK8ecuQeePyqNBbWve5/rmGUrI4qCdTAwRObtA+HCYWUmTW+8T0t+Ig7IBhIWlR0 NOb8Lckw3rvtiH43KLupM6DyMe3w1p6bJiwXabGMRY5KrJCXKnMVetvBgYa5YUSQ50OzQm+7KZa mCobRz/YYQjeJ74WBwFU1zqeVu7p14DgeIdw== X-Gm-Gg: ASbGncsSN9GLw9wtwpRIvzUSIlyLUEwtRmkb3P6aV/HF7NcxTTiIUiDuvOQiAhDz8XN VOxIg4oyb6q4de+hOhRu8prENDKulMEzL8Zxw0KHPCYpKSoqBM8/OJAxUPmLpPTsTXkDqVq+Z0b JbylAZMwWepreAKaElQcIsEFFluUh/hkW5nBOepKoFHCB0pPle7EK+zjnwGlRnmMQC6ylVeXuOm ZgFu1IDiBOcfi4gu8lcCgbMXETzId3U5Ai3k5WQtubDeCeetBCIn8vM9ZwC2IhOY9Y01FssrnSN wkw6Fp1KrBCj0VPOQF3UX+kBcpxCqlpu X-Received: by 2002:ac8:5f95:0:b0:46c:791f:bf56 with SMTP id d75a77b69052e-46c791fc14bmr389799471cf.1.1736896080376; Tue, 14 Jan 2025 15:08:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFauVeM+N8uZ0sh3dY0onunMx9Qth92WECogV8bnz00fM6yi4AE6QY1h/UVQiWhIuuraCnIPg== X-Received: by 2002:ac8:5f95:0:b0:46c:791f:bf56 with SMTP id d75a77b69052e-46c791fc14bmr389798831cf.1.1736896079803; Tue, 14 Jan 2025 15:07:59 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:07:59 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 06/16] migration: Synchronize all CPU states only for non-iterable dump Date: Tue, 14 Jan 2025 18:07:36 -0500 Message-ID: <20250114230746.3268797-7-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Do one shot cpu sync at qemu_savevm_state_complete_precopy_non_iterable(), instead of coding it separately in two places. Note that in the context of qemu_savevm_state_complete_precopy(), this patch is also an optimization for postcopy path, in that we can avoid sync cpu twice during switchover: before this patch, postcopy_start() invokes twice on qemu_savevm_state_complete_precopy(), each of them will try to sync CPU info. In reality, only one of them would be enough. For background snapshot, there's no intended functional change. Signed-off-by: Peter Xu --- migration/migration.c | 6 +----- migration/savevm.c | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index b33baab950..33c4824b68 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3622,11 +3622,7 @@ static void *bg_migration_thread(void *opaque) if (migration_stop_vm(s, RUN_STATE_PAUSED)) { goto fail; } - /* - * Put vCPUs in sync with shadow context structures, then - * save their state to channel-buffer along with devices. - */ - cpu_synchronize_all_states(); + if (qemu_savevm_state_complete_precopy_non_iterable(fb, false)) { goto fail; } diff --git a/migration/savevm.c b/migration/savevm.c index 5e56a5d9fc..92e77ca92b 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1531,6 +1531,9 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, Error *local_err = NULL; int ret; + /* Making sure cpu states are synchronized before saving non-iterable */ + cpu_synchronize_all_states(); + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (se->vmsd && se->vmsd->early_setup) { /* Already saved during qemu_savevm_state_setup(). */ @@ -1584,8 +1587,6 @@ int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only) trace_savevm_state_complete_precopy(); - cpu_synchronize_all_states(); - if (!in_postcopy || iterable_only) { ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy); if (ret) { From patchwork Tue Jan 14 23:07:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CBCD7C02183 for ; Tue, 14 Jan 2025 23:09:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq16-0001xL-5l; Tue, 14 Jan 2025 18:08:12 -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 1tXq13-0001uQ-Vc for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:09 -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 1tXq11-00044M-Di for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896086; 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=WlVGpZyH3jEvqbeBG9TEbCRFPM+u3fzxUZ2wn3/Cceo=; b=K/QqjsruTe+AvbY1cHvDjyZd1o5sVFhkkj+c96Y7M2f+xIJLwqoaihWs9SRUNh/IekKyTP BYfnT5A9W0je0KuoNvCPSp22mg2ZbNZNFx0dKZ5Sro85OB8tVf6NTGfoJrXgJIeCU8ySC3 iLtygO6/85NB4QBVBPozY8fvdkdNqcE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-519-lmpIoBDvNxyJWRhB8T2kIQ-1; Tue, 14 Jan 2025 18:08:03 -0500 X-MC-Unique: lmpIoBDvNxyJWRhB8T2kIQ-1 X-Mimecast-MFC-AGG-ID: lmpIoBDvNxyJWRhB8T2kIQ Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-46dd301a429so63825991cf.1 for ; Tue, 14 Jan 2025 15:08:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896082; x=1737500882; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WlVGpZyH3jEvqbeBG9TEbCRFPM+u3fzxUZ2wn3/Cceo=; b=Av3kDX6WC6azM649bmWk1hBWjpYVNzazxAzWtEnyLZ9wDvYGaW021869PBu566OAk7 Kf6Km+h4iAR0SA3LLZ0/wZBTi/hv2h4prJ4RXi0b9/WNmE0nhopraVoMvE12P/oevANN FWyCQr5N9/o+9wZIzyPO4Dt+g4Rw7b+skt/O4z49J1qaElMLl36QgMGL4WOY9s2U94mH c/8LEQAusKptYBRcnetmwE0zw9+FaMdGVgcnzYLQt6EJg+G++rhgnLwAt5Sn1+XNY7OJ ORF+gdiThlHI4HnWsx4lCOsls6cSoJpwc+IuQueLbMNmSQkkkmpdrmz1a9Zez1PtPkKx 17Dw== X-Gm-Message-State: AOJu0Yx6vgq3u6xqD8wKecwhDqMm43XNIvm+B9bcryvGRqwnp5S79yNj NwghTaHkg8cGKRVCDkIdFdN8VaGc5NdY2TjoLGskY+86uICR8MniZ56TFnCYBxH/ELKlQ5KvZxg PoVMZox3FJ8V0NfQBwAmrV2qtkJ4MlL1u09OIircAvL9fyfAZJRuhO+AG3ybXUu4KEkgL1TNdzh UfqkTapqmEpJkzT2ppntRzaKqmeWUT5BbC8w== X-Gm-Gg: ASbGncuIji5c7npICp3SyMVEUHH524u0y0t9xCneYQuynd/54c/1UsXB+hiqs1vWarR osMWkm5FQu9IYI+pboMsn2jZz6OAH/YEQ9ggi2kVSCzoNJECL06CbipxDHYXwdB62wthhU+BXqp PNT2tRsufKQEqYRj2vbZ43nz5vyJPpJrlzzWpUXnZNdWJaZ4WfE3l5v3gkg9RUp6B+bfMswgeF5 K02etLi8N+Pv0zC0yxngw9rbSqO9aMbdOvhAJew0BvmIElk32PCvSuXUDnJt8/0FG4ZmxguSl4g t9Cyfll2C8fVlJkyz6Pe26J2DY4Fd16g X-Received: by 2002:a05:622a:4714:b0:46c:7141:9087 with SMTP id d75a77b69052e-46c714190f1mr334145101cf.1.1736896081749; Tue, 14 Jan 2025 15:08:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQSrXmhW759nFP04QStqKNu2YGJ23xnFUYrhh9jrYz8SJsxhr88MCIH3tHdFJU6bbnmWFHtg== X-Received: by 2002:a05:622a:4714:b0:46c:7141:9087 with SMTP id d75a77b69052e-46c714190f1mr334144861cf.1.1736896081420; Tue, 14 Jan 2025 15:08:01 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:00 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 07/16] migration: Adjust postcopy bandwidth during switchover Date: Tue, 14 Jan 2025 18:07:37 -0500 Message-ID: <20250114230746.3268797-8-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Precopy uses unlimited bandwidth always during switchover, it makes sense because this is so critical and no one would like to throttle bandwidth during the VM blackout. OTOH, postcopy surprisingly didn't do that. There's one line that in the middle of the postcopy switchover it tries to switch to postcopy's specified max-postcopy-bandwidth, but even so it's somewhere in the middle which is strange. This patch brings the two modes to always use unlimited bandwidth for switchover, meanwhile only apply the postcopy max bandwidth after the switchover is completed. Signed-off-by: Peter Xu --- migration/migration.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 33c4824b68..13b7df0d5b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2502,7 +2502,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) int ret; QIOChannelBuffer *bioc; QEMUFile *fb; - uint64_t bandwidth = migrate_max_postcopy_bandwidth(); int cur_state = MIGRATION_STATUS_ACTIVE; /* @@ -2551,6 +2550,9 @@ static int postcopy_start(MigrationState *ms, Error **errp) goto fail; } + /* Switchover phase, switch to unlimited */ + migration_rate_set(RATE_LIMIT_DISABLED); + /* * Cause any non-postcopiable, but iterative devices to * send out their final data. @@ -2567,12 +2569,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) ram_postcopy_send_discard_bitmap(ms); } - /* - * send rest of state - note things that are doing postcopy - * will notice we're in POSTCOPY_ACTIVE and not actually - * wrap their state up here - */ - migration_rate_set(bandwidth); if (migrate_postcopy_ram()) { /* Ping just for debugging, helps line traces up */ qemu_savevm_send_ping(ms->to_dst_file, 2); @@ -2656,6 +2652,12 @@ static int postcopy_start(MigrationState *ms, Error **errp) } trace_postcopy_preempt_enabled(migrate_postcopy_preempt()); + /* + * Now postcopy officially started, switch to postcopy bandwidth that + * user specified. + */ + migration_rate_set(migrate_max_postcopy_bandwidth()); + return ret; fail_closefb: From patchwork Tue Jan 14 23:07:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C804FE77188 for ; Tue, 14 Jan 2025 23:09:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq14-0001ur-Su; Tue, 14 Jan 2025 18:08:10 -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 1tXq12-0001tv-Ra for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:08 -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 1tXq11-00044K-BZ for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896086; 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=o6ibT0N3eQDXuj76OU80+8wwd1uXT2Xl2UVx22v24lc=; b=iKRLUpJWORbAnNuNYZ6Sj7CKuvP16ICUzbpRy1MWMh9X+Ngoeebcsuv56gOhB/CZuMxs5P YDDk4pcVYzdJtsYR1gEA3+SwYIHpQgNLhnvNcGyy+xGUC7ZkOoFQcK1FHW5QNpKsxH79is rsvEf+FrhtsCnKgv0RVUGfuK0hmMbTM= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-qiZt72bHPESCaTtTSmYlxA-1; Tue, 14 Jan 2025 18:08:04 -0500 X-MC-Unique: qiZt72bHPESCaTtTSmYlxA-1 X-Mimecast-MFC-AGG-ID: qiZt72bHPESCaTtTSmYlxA Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6d8fe8a0371so96120666d6.1 for ; Tue, 14 Jan 2025 15:08:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896084; x=1737500884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o6ibT0N3eQDXuj76OU80+8wwd1uXT2Xl2UVx22v24lc=; b=H3pj+zd5hnqoDaTHvHz0b/V3Hjo7+Qgh5N0KeUSpzPhFxdIdj80+FJlG2elZ2gOPdD 13Eemi6O8Vkj0JWbBIlsxIfpxgx0w7pL3bsettilAyIpkbj1vyN/WHrgHofGDvrPVmcu TnXJCRoTBbeQUlu0OKk4GSvZRjfgKuzAt2wvsZwVv/h7AX684elJQFmSk0dI5N6rn1Nr xgkvxm4ASkJ1rKlvd2/4uifOo+dn3rJYiIegEALuQYVh0kk65965raSQ+lZ1CCMUDN92 zpaMzhYy1ryZ3iS8b66lPdCW3tLM9Ft9WuLaubmLfVzW2o6fWwn6Y4zUakSzhjE5RWCo 8CYw== X-Gm-Message-State: AOJu0YyBoOP4oXIKYt3OXoMMZxGbQKgFePaVW3qZnXcXUpvDyjABCQN1 GJ9QmdTMACRST877M283T/nS0bHX4iC8PGFmjy3gvH7pUueckExeVT0r0JHzAGZvMKSrwAN7cl4 i8axyBYpLnSaAKg08D08dhzMy2vxt9hOmJj5y4lkWbbYXYaTqtObbSI0RwISnlC2u/5SvPfK+BM y1NQl++zaU10h7J1cZbtLyhgGGq0vmCN+Asg== X-Gm-Gg: ASbGncsVmWa4cNHgR1lczOhsxJ8OLtATbDah7Wrbh+XoLloL1NAS4Bt8WBYRFmMRVvj U8DqbFXc1jYrhKUd1z7VxdtL1NS3nLDboaZGIBQmK4NPg4SoCvnw8qA8unbZLPBSvZwjU0y1jPe wGcxTXf5gcDXWuUoCWbb3ikbc/AMpbYMIUU8hxMaVzXI/1Omxs2awxeWD0qq2Dt4IC/V1yNEAm6 1zBronggCKNOknlYcRPv12e/4Liw79CMCrdpX/F11SDLr1ml3ISVUEz5MHXNtf9lS32zprHNv3J Q/7aVSYCU4KTC4puGcgBheDYfN0Ntofs X-Received: by 2002:a05:6214:528e:b0:6dd:b9a6:e626 with SMTP id 6a1803df08f44-6df9b1c4fa7mr450551336d6.8.1736896083755; Tue, 14 Jan 2025 15:08:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHez8lz2JlCPSMlbxZaVYgHjfiicZrlgkCHnsnYgnuTT8ML97EipTPzCC7k+YBFzBJW/eYbEQ== X-Received: by 2002:a05:6214:528e:b0:6dd:b9a6:e626 with SMTP id 6a1803df08f44-6df9b1c4fa7mr450550936d6.8.1736896083394; Tue, 14 Jan 2025 15:08:03 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:02 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 08/16] migration: Adjust locking in migration_maybe_pause() Date: Tue, 14 Jan 2025 18:07:38 -0500 Message-ID: <20250114230746.3268797-9-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In migration_maybe_pause() QEMU may yield BQL before waiting for a semaphore. However it yields the BQL too early, which logically gives it chance for the main thread to quickly take the BQL and modify the state to CANCELLING. To avoid such race condition from happening at all, always update the migration states within the BQL. It'll make sure no concurrent cancellation can ever happen. With that, IIUC there's chance we can remove the extra parameter in migration_maybe_pause() to update active state, but that'll be done separately later. Signed-off-by: Peter Xu --- migration/migration.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 13b7df0d5b..5c688059de 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2701,14 +2701,14 @@ static int migration_maybe_pause(MigrationState *s, * wait for the 'pause_sem' semaphore. */ if (s->state != MIGRATION_STATUS_CANCELLING) { - bql_unlock(); migrate_set_state(&s->state, *current_active_state, MIGRATION_STATUS_PRE_SWITCHOVER); + bql_unlock(); qemu_sem_wait(&s->pause_sem); + bql_lock(); migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, new_state); *current_active_state = new_state; - bql_lock(); } return s->state == new_state ? 0 : -EINVAL; From patchwork Tue Jan 14 23:07:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97EC2E77188 for ; Tue, 14 Jan 2025 23:10:17 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq2N-0004Bg-G9; Tue, 14 Jan 2025 18:09:32 -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 1tXq27-0003qS-B9 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:09:15 -0500 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 1tXq25-0004IM-GN for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:09:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896152; 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=irKgyuwlTgCopG55dQ+ETYiKtWcHjCzYi9viy9UqP5I=; b=W9RY3KorhVghtmo4Xw8+RNrKBJu7+XZ7Y5mPRTQ8bh10H8NcUwqJpwcuBUOwQ7MJXS3ItA ZlB2TrBP5ZsI2YZd35cqEAHmKi7G+JwPnNcfmPCxtt6Q1LQ7tV3RgezHRRepeGsH/5EmqZ Dyy4IBhDhcrizhjgkVIZ7YiIo7lNIRU= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-152-VpB0c27yPpOt808-YVBATQ-1; Tue, 14 Jan 2025 18:08:06 -0500 X-MC-Unique: VpB0c27yPpOt808-YVBATQ-1 X-Mimecast-MFC-AGG-ID: VpB0c27yPpOt808-YVBATQ Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6f3b93f5cso59843085a.0 for ; Tue, 14 Jan 2025 15:08:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896085; x=1737500885; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=irKgyuwlTgCopG55dQ+ETYiKtWcHjCzYi9viy9UqP5I=; b=X6UKw5FiwoKwHkGHBPVnZmz94Pq1h0OAWdwb4x1SE21tjRNum55vWOp7g7v6+pV4vP uuS2dNTmQNJbStC+BM8F0h1owY5R/7GidOxhSCzJsQ5KhqHn7owZ5XyTMNKhytdasbRv /RIQ4YNdYhG33yVtoPzQ+OJdVP19zVIprqPJwoQqRTg3wjZSDDJeE+FQll7ClBeA4SXw 0pHtQwsTSUft7AZQDaV3amlbRAUELJlu5ML0oZ5SrMoKpaFR0lSDphEHns8vIpeszfbZ MUEm4qJz+vJ0vfGWsnTrdPnwkyCKpKe6n/NhzofjV/Z5++j/6LuOKLZ128IQSX0Lm4ev Fxsg== X-Gm-Message-State: AOJu0YyDeQA6cv+wdvqN1R2oeais3dUwOuD9/EA2J1QisaMCbjWDqRyw PFEpspTaKBnA/s8iiPAxn+IaS+HaHSybJiyged6C5qb+CLqA9fRFWpMelrHvkjLp3wGrf5no/9/ zp0OiL4uQAN23CLlyhfbzozpDvo6fpRmqsbn8fACBX0sRNmXdisSR0y7c9kRAsmhrjdtRFw1RId k/WylfdjHATclmaOorYNFVZhE0eKmKVeZPRg== X-Gm-Gg: ASbGnctRVO4lBimVOVnIKAlA8hTTdwUWHP/gxoqK6ur+dMJplnc09ixJcP20Ke/M3/H hH+EwNkUUMDM4nGlIoA/LzQBtZNrtwFTJAZUOXfWBU/y3wbuUgRpu5uHItR2r4vHtFkKwQNcVLr Rx+xoW/+SaNENtq/UrIJToubAJhFyPzpzf46xOP+cXL9HbO4fck2mvkQ7n9AucUG4a6bFoQB4tr HkW/VD+q8j/1LtgjomhnSoni9L+XoDnqABFNtjtq6t/0UzXmSgNdMvBfpivVjXk6tTqjNrXcIzO QBU+cOaxYe8aAjpM4UKTfMMp1t/S1Sw7 X-Received: by 2002:ad4:5d68:0:b0:6d8:893b:2a13 with SMTP id 6a1803df08f44-6e192acacb8mr14123026d6.0.1736896085162; Tue, 14 Jan 2025 15:08:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsMXaZrSKXmWGtmuQ5k0JobhExFbGUbgkJjmQTuJfxe4fV5xRDGJdJhXw52VxqYhCAMd8OuQ== X-Received: by 2002:ad4:5d68:0:b0:6d8:893b:2a13 with SMTP id 6a1803df08f44-6e192acacb8mr14122736d6.0.1736896084835; Tue, 14 Jan 2025 15:08:04 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:03 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 09/16] migration: Drop cached migration state in migration_maybe_pause() Date: Tue, 14 Jan 2025 18:07:39 -0500 Message-ID: <20250114230746.3268797-10-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org I can't see why we must cache the state now after we avoided possible CANCEL race: that's the only thing I can think of that can modify the migration state concurrently with the migration thread itself. Make all the state updates to happen always, then we don't need to cache the state anymore. Signed-off-by: Peter Xu --- migration/migration.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5c688059de..5850c90c9f 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -102,9 +102,7 @@ static MigrationIncomingState *current_incoming; static GSList *migration_blockers[MIG_MODE__MAX]; static bool migration_object_check(MigrationState *ms, Error **errp); -static int migration_maybe_pause(MigrationState *s, - int *current_active_state, - int new_state); +static int migration_maybe_pause(MigrationState *s, int new_state); static void migrate_fd_cancel(MigrationState *s); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); @@ -2502,7 +2500,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) int ret; QIOChannelBuffer *bioc; QEMUFile *fb; - int cur_state = MIGRATION_STATUS_ACTIVE; /* * Now we're 100% sure to switch to postcopy, so JSON writer won't be @@ -2537,8 +2534,7 @@ static int postcopy_start(MigrationState *ms, Error **errp) goto fail; } - ret = migration_maybe_pause(ms, &cur_state, - MIGRATION_STATUS_POSTCOPY_ACTIVE); + ret = migration_maybe_pause(ms, MIGRATION_STATUS_POSTCOPY_ACTIVE); if (ret < 0) { error_setg_errno(errp, -ret, "%s: Failed in migration_maybe_pause()", __func__); @@ -2676,9 +2672,7 @@ fail: * migrate_pause_before_switchover called with the BQL locked * Returns: 0 on success */ -static int migration_maybe_pause(MigrationState *s, - int *current_active_state, - int new_state) +static int migration_maybe_pause(MigrationState *s, int new_state) { if (!migrate_pause_before_switchover()) { return 0; @@ -2701,21 +2695,19 @@ static int migration_maybe_pause(MigrationState *s, * wait for the 'pause_sem' semaphore. */ if (s->state != MIGRATION_STATUS_CANCELLING) { - migrate_set_state(&s->state, *current_active_state, + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_PRE_SWITCHOVER); bql_unlock(); qemu_sem_wait(&s->pause_sem); bql_lock(); migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, new_state); - *current_active_state = new_state; } return s->state == new_state ? 0 : -EINVAL; } -static int migration_completion_precopy(MigrationState *s, - int *current_active_state) +static int migration_completion_precopy(MigrationState *s) { int ret; @@ -2728,8 +2720,7 @@ static int migration_completion_precopy(MigrationState *s, } } - ret = migration_maybe_pause(s, current_active_state, - MIGRATION_STATUS_DEVICE); + ret = migration_maybe_pause(s, MIGRATION_STATUS_DEVICE); if (ret < 0) { goto out_unlock; } @@ -2782,11 +2773,10 @@ static void migration_completion_postcopy(MigrationState *s) static void migration_completion(MigrationState *s) { int ret = 0; - int current_active_state = s->state; Error *local_err = NULL; if (s->state == MIGRATION_STATUS_ACTIVE) { - ret = migration_completion_precopy(s, ¤t_active_state); + ret = migration_completion_precopy(s); } else if (s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE) { migration_completion_postcopy(s); } else { @@ -2826,8 +2816,7 @@ fail: error_free(local_err); } - migrate_set_state(&s->state, current_active_state, - MIGRATION_STATUS_FAILED); + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_FAILED); } /** From patchwork Tue Jan 14 23:07:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5E868C02183 for ; Tue, 14 Jan 2025 23:08:47 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1E-000204-VH; Tue, 14 Jan 2025 18:08:20 -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 1tXq19-0001ze-2u for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:15 -0500 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 1tXq17-000478-A2 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896091; 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=7tDkWWg6+jos1+qRgaPmbYXKxwn6YXWcJ9OlhS4rNJA=; b=hjQbJBRdGo9RQWUCZqbqXTkuAmSgIDOEcMQGbLV8xJNCMGNZKXqj4RMqSQub5+oI96sOS3 kh+XeMooEqFO+L/P6MtoWdOBquHvZNFFY9zks1omQKznz32btHQUzpXeChWN2mS5geNdK7 +krGuCgDo9VeQpDA66yE6CDJYMCOLq4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-Vd6OOj2ONEyiIyGW-8ujAA-1; Tue, 14 Jan 2025 18:08:07 -0500 X-MC-Unique: Vd6OOj2ONEyiIyGW-8ujAA-1 X-Mimecast-MFC-AGG-ID: Vd6OOj2ONEyiIyGW-8ujAA Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6d92efa9ff4so92717156d6.2 for ; Tue, 14 Jan 2025 15:08:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896087; x=1737500887; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7tDkWWg6+jos1+qRgaPmbYXKxwn6YXWcJ9OlhS4rNJA=; b=MNr7c1Doc8XW48lb3rfognaaqpCwiJjV8X7uBMsSZkVWuREnsQM4MdT7ky11ZHq0uZ AsM42HoGOXbjOcCCIAlOXX1+s5fSv00PbczWqSa/aUi2BPWVQQ8wQG/7wR3etGLsPQeX EnGSFEpWaILG3bsVFOBRxQ6gaW0MFAd6D7zanzHDJHo08il0DeD5/iPYPx20/0CEdBIx Ow5kLTrgj50QtfYjwYqLwQ12yYh2WnhDbspC24uA9Y7EO62zV1K6KhNasy3OTU5r9iBc LmJTeyxMnESuewZcg7WIRN+kqaayTwhZI7Fe7S9ZGxAD8kqyxRLfl5E0Uh9fBRf4bPn4 UiIQ== X-Gm-Message-State: AOJu0Yyjv+wclgyhBi8z5OgqgaCA0gzmsFD/363DBqV2d/gFnkseWx1z lCHGN3O9hJEAaxbiDjP8WW4v/tPkVPEiUmp+9PcPmwkpmxFq9sLhmeMAuGV06OUdTXwTygLz3nn /JGX/iEWSgBy9tVbB/A2QuvPA10jiPbu6aPSSh52DmbV0vDolskji7GoXahgrGfTAzeW3iqFZfC eQWDGJwhhEbDrFRb7PWkclEWkTGzMQLuVJtQ== X-Gm-Gg: ASbGncvJsDMxQAq1dCG83TRf23hod3dP5q6do0HyV6k5yHY+g+ClgiI0nzEvszO5Pum P5bTMrjaIStHi29McHrXTLbqJNSYOavc3GuvF4ZbmKZkUEFrdkfOyPSoXR/y7VrFSnHQC/JLyYB LrFMIzxV2ww4cm1xl+WHL+Dcxav9hB2vTKDg7WGIduUgBCDqfyecTQjS6M1OYkLmx822oye/9yo tpN+GbZb3f7fGk4InttSVxGw8rA9jFlae2CReAkh7GA83NUh6/flFN1Ne04vz0fY07WiZoCn0yw JF0iebHpcHI67KNN1aJ6C9B9JRbDj364 X-Received: by 2002:a05:6214:e83:b0:6d4:3437:d858 with SMTP id 6a1803df08f44-6df9b22e404mr410183856d6.25.1736896087067; Tue, 14 Jan 2025 15:08:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEspMYjE2J2V7F2QCz2ZDLl4X3BwYy/S9aH7DTn3ewShqr7tTWsK7nWJCVDOHTbAH7K80ptyA== X-Received: by 2002:a05:6214:e83:b0:6d4:3437:d858 with SMTP id 6a1803df08f44-6df9b22e404mr410183496d6.25.1736896086719; Tue, 14 Jan 2025 15:08:06 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:05 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 10/16] migration: Take BQL slightly longer in postcopy_start() Date: Tue, 14 Jan 2025 18:07:40 -0500 Message-ID: <20250114230746.3268797-11-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org This paves way for some follow up patch to modify migration states at the end of postcopy_start(), which should better be with the BQL so that there's no way of concurrent cancellation. So we'll do something slightly more with BQL but they're really trivial, hopefully nothing will really chance with this. A side benefit is we can drop another explicit lock() in failure path. Signed-off-by: Peter Xu --- migration/migration.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 5850c90c9f..f644a6306b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2626,8 +2626,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) migration_downtime_end(ms); - bql_unlock(); - if (migrate_postcopy_ram()) { /* * Although this ping is just for debug, it could potentially be @@ -2643,7 +2641,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) ret = qemu_file_get_error(ms->to_dst_file); if (ret) { error_setg_errno(errp, -ret, "postcopy_start: Migration stream error"); - bql_lock(); goto fail; } trace_postcopy_preempt_enabled(migrate_postcopy_preempt()); @@ -2654,6 +2651,8 @@ static int postcopy_start(MigrationState *ms, Error **errp) */ migration_rate_set(migrate_max_postcopy_bandwidth()); + bql_unlock(); + return ret; fail_closefb: From patchwork Tue Jan 14 23:07:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5750E77188 for ; Tue, 14 Jan 2025 23:09:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1c-00024p-NK; Tue, 14 Jan 2025 18:08:44 -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 1tXq1D-00020K-A3 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:20 -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 1tXq1B-0004A4-4l for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896093; 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=DoRPUxclEIuZm3ns0XxOQfYN1niMrBQ1FrIS1kOLfnY=; b=O35wF0HOKpkaRa9S6ntjJmAw1QkM6ugohmqmY0FBshs7u1kC0N48WExrfNDz7dLdqU4WYe 4BxfA1PQOXp8IYeSxQyJOgojpWGFFFZBxAUEfDYeAQ2ZAJWyQ+rlhIztZB2bnXxNKHXtv2 oaURtk3r/UoeTaIB82KyefmZNbLaLWI= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-5-wvB-2HlSMe-Aj46pHcUCKA-1; Tue, 14 Jan 2025 18:08:10 -0500 X-MC-Unique: wvB-2HlSMe-Aj46pHcUCKA-1 X-Mimecast-MFC-AGG-ID: wvB-2HlSMe-Aj46pHcUCKA Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-46799aa9755so152604831cf.0 for ; Tue, 14 Jan 2025 15:08:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896089; x=1737500889; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DoRPUxclEIuZm3ns0XxOQfYN1niMrBQ1FrIS1kOLfnY=; b=JDXB0dyIqL7q5YTnwsndBrVJcAnrJCvgQlS7Pw/vrwyofwWo+w9UdDxDjUBEPeYZuJ hxAmSDTVBg6wx2t23Md7Zo7I576VvGAHFcagMF8jf4CdeDkqpZ2yvR8TMuCHL6BTqxp7 P2oDlmw3UPiqx/AZBg7Eo7Emcp3JOkuoU+wX2Hc4BRDD/1yddeoocRsuhFyMEp2UddH8 KHdAoBlp9FRRUjLWZLqvaD4KtGYdERWKmhLPsyY6tlMks1jNkoHuJwy9vs5w7mLoxUim 07UtrmJCCPa1Y7FRgoDSM5nG6DLtjX3pADhqacSdhVadDVlak+4qHowwjoyGyqHSXRH3 I6Zw== X-Gm-Message-State: AOJu0YwI/O4dS1pQ1ZXVGbm9FfGZ1xWS9h1aNPZ7St/yxx/0aNPN7m3P kQu7+jR4sFywfJJfM6CQq4HWv3/IVyGpjs/mtykIpzI6ofC1Sty21MCE6gmJ0PI8l6x4eOOf7v3 LzagYXMQ2oCYt+X/t342AgUw0PcIM96RInyS5qYuTWYJb7I0Oi3mXgNKx1hJSMypm/CspiUiA5Q pGX9Fda5M7KQXLanCimovXLYMRMs7PzCKTcw== X-Gm-Gg: ASbGncsoGRNpI/+zh9AqV9Ok1LeADov71FtV8ipOz6kQJ9JlFf9ypak6bR6iUdUfq34 sv+JAbiL1gtiYHDzIpzf1j2UdI6c5Gc6rPxfkCEqFrfjRS+03bnIFlf042/VF5o8P5rofc9thtd rQ84rOk2GB25kTV3EPkHFrrthHQWYw0qRTIiur7wIseCzcxC/FAjj9hmExkvsYmSTaCF4yac2oe O/sn2uc7VihVbV8Ny51teQIH8NpepSEpny1415OVweUWjCT4Ks1GjdryNK/uIAwz9vzf+HSVyrC LZG/fJRWzDsXokFg2eHy3C0f3xImOeOy X-Received: by 2002:ac8:5955:0:b0:467:8765:51ae with SMTP id d75a77b69052e-46c71081664mr419945351cf.39.1736896089058; Tue, 14 Jan 2025 15:08:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGe5AtZZUYYt7+5B5t1idUkM7mY3p3t6lvIidFL8v3ea8e3Qayq9UVqeGl6uV+XIpGLtaKF2g== X-Received: by 2002:ac8:5955:0:b0:467:8765:51ae with SMTP id d75a77b69052e-46c71081664mr419944661cf.39.1736896088345; Tue, 14 Jan 2025 15:08:08 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:07 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 11/16] migration: Notify COMPLETE once for postcopy Date: Tue, 14 Jan 2025 18:07:41 -0500 Message-ID: <20250114230746.3268797-12-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Postcopy invokes qemu_savevm_state_complete_precopy() twice, that means it'll invoke COMPLETE notify twice.. also twice the tracepoints that marking precopy complete. Move that notification (along with the tracepoint) out to the caller, so that postcopy will only notify once right at the start of switchover phase from precopy. When at it, rename it to suite the file now it locates. For precopy, there should have no functional change except the tracepoint has a name change. For the other two users of qemu_savevm_state_complete_precopy(), namely: qemu_savevm_state() and qemu_savevm_live_state(): the notifier shouldn't matter because they're not precopy at all. Now in these two contexts (aka, "savevm", and "colo") sometimes the precopy notifiers will still be invoked, but that's outside the scope of this patch. Signed-off-by: Peter Xu --- migration/migration.c | 15 +++++++++++++++ migration/savevm.c | 7 ------- migration/trace-events | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index f644a6306b..2c5674c2ae 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -127,6 +127,17 @@ static void migration_downtime_end(MigrationState *s) } } +static void precopy_notify_complete(void) +{ + Error *local_err = NULL; + + if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) { + error_report_err(local_err); + } + + trace_migration_precopy_complete(); +} + static bool migration_needs_multiple_sockets(void) { return migrate_multifd() || migrate_postcopy_preempt(); @@ -2549,6 +2560,8 @@ static int postcopy_start(MigrationState *ms, Error **errp) /* Switchover phase, switch to unlimited */ migration_rate_set(RATE_LIMIT_DISABLED); + precopy_notify_complete(); + /* * Cause any non-postcopiable, but iterative devices to * send out their final data. @@ -2738,6 +2751,8 @@ static int migration_completion_precopy(MigrationState *s) migration_rate_set(RATE_LIMIT_DISABLED); + precopy_notify_complete(); + ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false); out_unlock: bql_unlock(); diff --git a/migration/savevm.c b/migration/savevm.c index 92e77ca92b..9aef2fa3c9 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1578,15 +1578,8 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only) { int ret; - Error *local_err = NULL; bool in_postcopy = migration_in_postcopy(); - if (precopy_notify(PRECOPY_NOTIFY_COMPLETE, &local_err)) { - error_report_err(local_err); - } - - trace_savevm_state_complete_precopy(); - if (!in_postcopy || iterable_only) { ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy); if (ret) { diff --git a/migration/trace-events b/migration/trace-events index b82a1c5e40..ec3c9d0ffe 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -44,7 +44,6 @@ savevm_state_resume_prepare(void) "" savevm_state_header(void) "" savevm_state_iterate(void) "" savevm_state_cleanup(void) "" -savevm_state_complete_precopy(void) "" vmstate_save(const char *idstr, const char *vmsd_name) "%s, %s" vmstate_load(const char *idstr, const char *vmsd_name) "%s, %s" vmstate_downtime_save(const char *type, const char *idstr, uint32_t instance_id, int64_t downtime) "type=%s idstr=%s instance_id=%d downtime=%"PRIi64 @@ -193,6 +192,7 @@ migrate_transferred(uint64_t transferred, uint64_t time_spent, uint64_t bandwidt process_incoming_migration_co_end(int ret, int ps) "ret=%d postcopy-state=%d" process_incoming_migration_co_postcopy_end_main(void) "" postcopy_preempt_enabled(bool value) "%d" +migration_precopy_complete(void) "" # migration-stats migration_transferred_bytes(uint64_t qemu_file, uint64_t multifd, uint64_t rdma) "qemu_file %" PRIu64 " multifd %" PRIu64 " RDMA %" PRIu64 From patchwork Tue Jan 14 23:07:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF086C02188 for ; Tue, 14 Jan 2025 23:08:48 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1U-00023F-Rv; Tue, 14 Jan 2025 18:08:37 -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 1tXq1D-00020J-9R for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:20 -0500 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 1tXq19-0004Bp-LB for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896095; 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=Hhl80ZRJ0L6Cz/BkuObye4iJe3Q+DTb7+J4GtiBMHrE=; b=CFr6mfTTmnhQsCotihf8NwEVahmB7Ldvbl40lDM6wGccXCT2TCVAWP05N2PtYusAzNU+UP zCZMk88/Wrkv5xnO9ky0y3ReFu/68ny4QF2SS/P6j54BYahDZRX9/VRh6SyibMxSh9uu2E czhsdi7sUceYcH6xY3VCVltyigMPKec= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-138-A_sMUyqmON2UeIlqji1sOw-1; Tue, 14 Jan 2025 18:08:13 -0500 X-MC-Unique: A_sMUyqmON2UeIlqji1sOw-1 X-Mimecast-MFC-AGG-ID: A_sMUyqmON2UeIlqji1sOw Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-4679aeb21e6so101066591cf.0 for ; Tue, 14 Jan 2025 15:08:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896092; x=1737500892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hhl80ZRJ0L6Cz/BkuObye4iJe3Q+DTb7+J4GtiBMHrE=; b=bX7h6x2oLyOE5F/O9H8YAHLlChBkuv7SvoXnWp1QwxwGyO2L7awNJsEXYYLAPxeerY qfsiEvofI9S98K9bhaR5KZLZpZ15XjCKEyvgyGbC7hbKDveg1cFKE4NlHzMiLP6VUgXi tECblsLiPmWvhikE2YgYqPFfpvMR6Zjwi+Q0WRQXMA4IatVeQwzImpwrSGaVi8XgdG1v G9og+O9RPu3HDLtH1gx8pVxELGNppPuNbCQcIbIs8gFTC7S9S/Ad2ZyR2A/wpXp6RMRL oBN/1AjvyVJBzUyIzGd36y0o12xMJpZaDut8j4UcymfmKeIjJiPZ/6knIPFUTUMZxuNq hqLg== X-Gm-Message-State: AOJu0YwgRZ18v8CqNDSke/EeSHhww/oruopIlyIRzPPtcQe9NiYnj/uI 39sJc+pGS7HOVNOCxOjPUIFOXJblE2ZX0DnPV6tmdpE3E5cccafIFKfAmNwQdlTEKeV5vlvd8CD UowLgpvj/fBaDOLnPekqjAtU1k9VsbkrNuq6gNIyo6ylGpEc6I3c2XuYlDz7bw4qTBkdArykahM dmw2tY4iYVMMnoW51Y14U/8R9YeQ6ZjBlFsg== X-Gm-Gg: ASbGncud4x2CyB/jDsge1N/aL6f88vr+FAcjrn9p6C7BoKtKLKMxwwHHVjMC+MmsdcA yTY/SnS36WmHnwu4ShcH761JfTteKx6TKMnu5iQYoSmTDuYCSvZ5vyFNLEE+1Guv/pS/2pGJpi/ CMsz98NO/jLkesdnBEgQev1mV2OUCwgGpc3088x93PHQiForX6GKCwckFRPmuvA24UlVRetY9LB YnZol4XbxHYB5Gc5hWoI0wubCi5/QvhpfmBymjJOVxiMpgPGIhoH20oSdo7okoEp27kgnJwR0vy 2oBq+bAY6dZj3LkDqrP/lwYmXhFl4KXK X-Received: by 2002:a05:622a:1342:b0:467:6e45:218d with SMTP id d75a77b69052e-46c70fd4538mr435056851cf.3.1736896090730; Tue, 14 Jan 2025 15:08:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwHJpZGpxw4K2ScjXB4dQY9Z0MRzHAGFy+LqFYRXcSoFOeIYemH54XbXHjLm/XZZ6d3CxFLQ== X-Received: by 2002:a05:622a:1342:b0:467:6e45:218d with SMTP id d75a77b69052e-46c70fd4538mr435056431cf.3.1736896090322; Tue, 14 Jan 2025 15:08:10 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:09 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 12/16] migration: Unwrap qemu_savevm_state_complete_precopy() in postcopy Date: Tue, 14 Jan 2025 18:07:42 -0500 Message-ID: <20250114230746.3268797-13-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Postcopy invokes qemu_savevm_state_complete_precopy() twice for a long time, and that caused way too much confusions. Let's clean this up and make postcopy easier to read. It's actually fairly straightforward: postcopy starts with saving non-postcopiable iterables, then later it saves again with non-iterable only. Move these two calls out makes everything much easier to follow. Otherwise it's very unclear what qemu_savevm_state_complete_precopy() did in either of the calls. No functional change intended. Signed-off-by: Peter Xu --- migration/savevm.h | 1 + migration/migration.c | 13 +++++++++++-- migration/savevm.c | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/migration/savevm.h b/migration/savevm.h index c48a53e95e..7957460062 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -44,6 +44,7 @@ void qemu_savevm_state_pending_exact(uint64_t *must_precopy, uint64_t *can_postcopy); void qemu_savevm_state_pending_estimate(uint64_t *must_precopy, uint64_t *can_postcopy); +int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy); void qemu_savevm_send_ping(QEMUFile *f, uint32_t value); void qemu_savevm_send_open_return_path(QEMUFile *f); int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len); diff --git a/migration/migration.c b/migration/migration.c index 2c5674c2ae..a8fe423a2b 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2566,7 +2566,11 @@ static int postcopy_start(MigrationState *ms, Error **errp) * Cause any non-postcopiable, but iterative devices to * send out their final data. */ - qemu_savevm_state_complete_precopy(ms->to_dst_file, true); + ret = qemu_savevm_state_complete_precopy_iterable(ms->to_dst_file, true); + if (ret) { + error_setg(errp, "Postcopy save non-postcopiable iterables failed"); + goto fail; + } /* * in Finish migrate and with the io-lock held everything should @@ -2605,7 +2609,12 @@ static int postcopy_start(MigrationState *ms, Error **errp) */ qemu_savevm_send_postcopy_listen(fb); - qemu_savevm_state_complete_precopy(fb, false); + ret = qemu_savevm_state_complete_precopy_non_iterable(fb, true); + if (ret) { + error_setg(errp, "Postcopy save non-iterable device states failed"); + goto fail_closefb; + } + if (migrate_postcopy_ram()) { qemu_savevm_send_ping(fb, 3); } diff --git a/migration/savevm.c b/migration/savevm.c index 9aef2fa3c9..0ddc4c8eb5 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1477,7 +1477,6 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f) qemu_fflush(f); } -static int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy) { int64_t start_ts_each, end_ts_each; From patchwork Tue Jan 14 23:07:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99034C02183 for ; Tue, 14 Jan 2025 23:10:34 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1M-00021o-QF; Tue, 14 Jan 2025 18:08:30 -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 1tXq1B-000206-Cy for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:20 -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 1tXq18-0004Aa-Nv for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896093; 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=/OGYzU0DY1992OqiRiyqmD3H3jqkTaE03aIsLwBHxW8=; b=E9qpH9kiHA5RJTxu/+/5qEbQGGIELEmY7S+bwJyDMPMdf1gSgQ272VWVSLPs2d5FXgU72d 66ScOP8VMoM1Wif8GHxA+11HMEoyUk5GQmqyN/oCwNvT2L2mM4+kcvTkn6XjLSbD5doVHO ngSuhyM1WJ0vFhEfC/fEk6fRLK13y8g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-3Dr6LF8_OLyNe-QJUVvOIQ-1; Tue, 14 Jan 2025 18:08:12 -0500 X-MC-Unique: 3Dr6LF8_OLyNe-QJUVvOIQ-1 X-Mimecast-MFC-AGG-ID: 3Dr6LF8_OLyNe-QJUVvOIQ Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-7b6f943f59dso1044006885a.2 for ; Tue, 14 Jan 2025 15:08:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896092; x=1737500892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/OGYzU0DY1992OqiRiyqmD3H3jqkTaE03aIsLwBHxW8=; b=AkioRxH7J/hMTFbOdB2r7vrcIOe1IHysWHLME/xMu6QZI7qHTh9cwDNpaMGVrmJegb eNvPujSJQyYkkAQ17ZtgMkmYS9RzvexGfy/1pWGtUkxvxSRUnayAhDvRotmavZwWiDpE 5T6AQkzpr+k7jsjxIh7Z2VSG/2y1OU0PZnlxn3rezF/6LJOERu+HZtdw8X9VD5IP2vvN AAyOO/wHGUnh4+sJpa6eEyhJzv/KpsG7PEUhPmExtkJd8ZS930HrHH8FoxfZv8wtZ4mm s+TS1TocSX9M55mpBc+cFadtrgj9PfbYvyIuTUFdrVcykadvpnTZVLciz3Chjjyl7jtX 8sSQ== X-Gm-Message-State: AOJu0YzIPQ1qGLQvu632fiduZU1HlhH4RgQBAm3ZShvCGHZ9liGOxOC2 uDIlHwdPp/zwvUjU/Sh+DA3w3fKkbumGSUW3/u6i4fMc9sBxI0cM36VE45qSSjDnMNuKex3j08X uhSkonv+dTJqroNU7uGaAJlZogN+3vTS7NsaPqVh2lAVdXV+BqhBzhYLcvldLrq3z+tJYvubiI+ Gg+MZ1Jr0AwpgYrgD1+1SYoxsddWmgyV2P9w== X-Gm-Gg: ASbGnctLUkIfGXvekiAWbYrhHHWnkfP0eFJF8SesOVDTb2QGukUAugbx6otyTflbyqP iroEacTWeg5tOBZkv9COav+1GIYh7XhIVpqi++Wq+lkz8ViMF1JEDiLBGsicnHv2akq6Q+faIEl kwdCYmoalJJHia/yZD+NHFSpnMaF8dzATILduj6VlnBXqtbUZ2cqsX0R3AoFvspNMPO8WdAHCjU qbmgNY3Z+/mfK+xWWHsfSlx84wSNJuqt28u4cw42dcVyHiB6fz7vkPbQdxRXb+ZVSXlf2xQQsjX rClcc2gXJ9E328MF3y5qPkNy0pa6cx7M X-Received: by 2002:a05:620a:469f:b0:7b6:d4b9:b5a7 with SMTP id af79cd13be357-7bcd9727ab1mr4589246985a.6.1736896092032; Tue, 14 Jan 2025 15:08:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGf9rehkQlWr1MW0F7Utef7epLonee4nDlLVc6KVH/qCGmygEVHKZotruvA8u/MYsWftYuXIw== X-Received: by 2002:a05:620a:469f:b0:7b6:d4b9:b5a7 with SMTP id af79cd13be357-7bcd9727ab1mr4589242585a.6.1736896091585; Tue, 14 Jan 2025 15:08:11 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:10 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 13/16] migration: Cleanup qemu_savevm_state_complete_precopy() Date: Tue, 14 Jan 2025 18:07:43 -0500 Message-ID: <20250114230746.3268797-14-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now qemu_savevm_state_complete_precopy() is never used in postcopy, clean it up as in_postcopy==false now unconditionally. Signed-off-by: Peter Xu --- migration/savevm.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 0ddc4c8eb5..bc375db282 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1577,25 +1577,19 @@ int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f, int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only) { int ret; - bool in_postcopy = migration_in_postcopy(); - if (!in_postcopy || iterable_only) { - ret = qemu_savevm_state_complete_precopy_iterable(f, in_postcopy); + ret = qemu_savevm_state_complete_precopy_iterable(f, false); + if (ret) { + return ret; + } + + if (!iterable_only) { + ret = qemu_savevm_state_complete_precopy_non_iterable(f, false); if (ret) { return ret; } } - if (iterable_only) { - goto flush; - } - - ret = qemu_savevm_state_complete_precopy_non_iterable(f, in_postcopy); - if (ret) { - return ret; - } - -flush: return qemu_fflush(f); } From patchwork Tue Jan 14 23:07:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1894C02183 for ; Tue, 14 Jan 2025 23:09:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1d-00025W-8n; Tue, 14 Jan 2025 18:08:45 -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 1tXq1H-00021L-3h for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:25 -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 1tXq1E-0004CV-6v for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896098; 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=pmFaOzluSBJlmHuYFILUjrWqsbv31ND4/DIPaTdh/4M=; b=fhvUjuXysOqT/PmJMXZt9vCzzRQdUl2BCvRnq1gl37HgXOaki6s0yC93ld8sxk3/ax7BZl q7Vshbta4Wgaxee37DPGA6KAwTkVVtrz9LjI0ZQyodbgtlnM2/vuPv87LLUpLAgxpYafxQ HnNpt3rijZyMxKpxxnA3+WtuQ+xKlqE= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-131-f-ZSmMGgPFCpt4W8JCPcIw-1; Tue, 14 Jan 2025 18:08:16 -0500 X-MC-Unique: f-ZSmMGgPFCpt4W8JCPcIw-1 X-Mimecast-MFC-AGG-ID: f-ZSmMGgPFCpt4W8JCPcIw Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-4678b42cbfeso122244421cf.3 for ; Tue, 14 Jan 2025 15:08:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896094; x=1737500894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmFaOzluSBJlmHuYFILUjrWqsbv31ND4/DIPaTdh/4M=; b=jO7lh63sBDgooOD5LA4E5xLuwqX4erzuOk40FkvGH+iJ32HbpuA2q311OMAWoRLGes jHHzyjmzZ0hwWgSkrcVxQOiK3iaEGId9zvZUwHvLzse7MM+oOyFdHZ8hI/ePionQjZli o4jHwCRDlv0mfEs845qFnlfnmAAeVIZwNN5tfUIuh1/SybO+zNbe2iZ1mjeZoO5LCayp IovmA6Khlf3bIDMQE7VycXRQPEOfEWPzXfpFxF21k33D2WMIRAj0+ulo8Jm66hjVNeDh IVxcs4/XK30mvmJ6xVwd560wwulPhkwnh9Y4rJxdmKX8As9QwehIKChHakKsSre4t48k tD7A== X-Gm-Message-State: AOJu0YytRIWvVRamWGWskucwbzSFXAOY8CSJDUFijczxv6U+A/sMYaRD sor0JLyT4TElYbd1+BuUzgfLJDBgeVxxxnRMhn7QLWyLaAcfQBG8EMbhl0DTJQ2/1Gb3+rJvowD u6KDCJorRLWVBWrsJZA5A2ssiYjb6sdLkxf8N11fFyEEpxdDGnFnXy6jdxYQ/8wokogNDF5upIh +3dY84VjhdRYOQiC5CK9pWjCxMnbj99a4t7g== X-Gm-Gg: ASbGncu7i3Wai5bIBaoWaXafg8+6Iooc//30ikI0oSIBupakPJAAHxYG/rp/XqILJvv S2HItw5D5dt+XuzzAOOU06GgmF6KT9g+r6pV3cE1RF+AQNIdYmOXLEjBIr4zlaRWCVobq1gqDSD Ues630AD4XFahWeaczdvu+jocnTTv8J0O0A+TkUktimzC2OvtxNIWWZeSf9mrmMc1GTWAMKBfU0 Wwb7vzg1tiRJHJKjcFkX+hXAsQf95a2zwCl3nGC6Q5E4aWVyGw4VPkk7h5IsFu3jV6S1WSYzJ2m ZuWIrDhrhXlukqmkbOI3+Kvxj0hWiv5t X-Received: by 2002:ac8:5746:0:b0:467:50d0:8869 with SMTP id d75a77b69052e-46c71004b3amr464993461cf.18.1736896094006; Tue, 14 Jan 2025 15:08:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5Lsm5vDavLlde2FVr8DkN0Iyih2gUZK4xiZZtJVOmCJwrrBV6VsmSTUE/8fcyqaR4rYTDMg== X-Received: by 2002:ac8:5746:0:b0:467:50d0:8869 with SMTP id d75a77b69052e-46c71004b3amr464993021cf.18.1736896093549; Tue, 14 Jan 2025 15:08:13 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:12 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas , Jiri Denemark , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , "Dr. David Alan Gilbert" Subject: [PATCH 14/16] migration: Always set DEVICE state Date: Tue, 14 Jan 2025 18:07:44 -0500 Message-ID: <20250114230746.3268797-15-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 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.063, 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_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DEVICE state was introduced back in 2017: https://lore.kernel.org/qemu-devel/20171020090556.18631-1-dgilbert@redhat.com/ Quote from Dave's cover letter, when the pre-switchover phase was enabled, the state transition looks like this: The precopy flow is: active->pre-switchover->device->completed The postcopy flow is: active->pre-switchover->postcopy-active->completed To supplement above, when the cap is not enabled: The precopy flow is: active->completed The postcopy flow is: active->postcopy-active->completed It works for us, though we have some code just to special case these state transitions, so the DEVICE state currently is special only to precopy, and only conditionally. I had a quick discussion with Libvirt developers, it turns out that this may not be necessary. IOW, it seems okay we can have DEVICE state to be generic, so that we don't have over-complicated state machines. It not only helps align all the migration state machine, help cleanup the code path especially on pre-switchover handling (see the patch itself), another side benefit is we can unconditionally have a specific state to mark the switchover phase, which might be helpful for debugging too. This patch makes the DEVICE state to be present always, marking that source QEMU is switching over. Then the state machine will be always as simple as: active-> [pre-switchover->] -> device -> [postcopy-active->] -> complete After the change, no matter whether pre-switchover or postcopy is enabled or not, we always have DEVICE state showing the switchover phase. When pre-switchover enabled, we'll have an extra stage before that. When postcopy is enabled, we'll have an extra stage after that. A few qtests need touch up in QEMU tree for this change: - A few iotest outputs (194, 203, 234, 262, 280) - Teach libqos's migrate() on "device" state Cc: Jiri Denemark Cc: Daniel P. BerrangĂ© Cc: Dr. David Alan Gilbert Signed-off-by: Peter Xu --- qapi/migration.json | 7 +++- migration/migration.c | 82 +++++++++++++++++++++++-------------- tests/qtest/libqos/libqos.c | 3 +- tests/qemu-iotests/194.out | 1 + tests/qemu-iotests/203.out | 1 + tests/qemu-iotests/234.out | 2 + tests/qemu-iotests/262.out | 1 + tests/qemu-iotests/280.out | 1 + 8 files changed, 64 insertions(+), 34 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index a605dc26db..86d2342e1f 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -158,8 +158,11 @@ # # @pre-switchover: Paused before device serialisation. (since 2.11) # -# @device: During device serialisation when pause-before-switchover is -# enabled (since 2.11) +# @device: During device serialisation (also known as switchover phase). +# Before 9.2, this is only used when (1) in precopy, and (2) when +# pre-switchover capability is enabled. After 10.0, this state will +# always be present for every migration procedure as the switchover +# phase. (since 2.11) # # @wait-unplug: wait for device unplug request by guest OS to be # completed. (since 4.2) diff --git a/migration/migration.c b/migration/migration.c index a8fe423a2b..2a95081b6c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -102,7 +102,7 @@ static MigrationIncomingState *current_incoming; static GSList *migration_blockers[MIG_MODE__MAX]; static bool migration_object_check(MigrationState *ms, Error **errp); -static int migration_maybe_pause(MigrationState *s, int new_state); +static bool migration_switchover_start(MigrationState *s); static void migrate_fd_cancel(MigrationState *s); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); @@ -2530,11 +2530,6 @@ static int postcopy_start(MigrationState *ms, Error **errp) } } - if (!migrate_pause_before_switchover()) { - migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE, - MIGRATION_STATUS_POSTCOPY_ACTIVE); - } - trace_postcopy_start(); bql_lock(); trace_postcopy_start_set_run(); @@ -2545,10 +2540,8 @@ static int postcopy_start(MigrationState *ms, Error **errp) goto fail; } - ret = migration_maybe_pause(ms, MIGRATION_STATUS_POSTCOPY_ACTIVE); - if (ret < 0) { - error_setg_errno(errp, -ret, "%s: Failed in migration_maybe_pause()", - __func__); + if (!migration_switchover_start(ms)) { + error_setg(errp, "migration_switchover_start() failed"); goto fail; } @@ -2673,6 +2666,10 @@ static int postcopy_start(MigrationState *ms, Error **errp) */ migration_rate_set(migrate_max_postcopy_bandwidth()); + /* Now, switchover looks all fine, switching to postcopy-active */ + migrate_set_state(&ms->state, MIGRATION_STATUS_DEVICE, + MIGRATION_STATUS_POSTCOPY_ACTIVE); + bql_unlock(); return ret; @@ -2689,14 +2686,39 @@ fail: } /** - * migration_maybe_pause: Pause if required to by - * migrate_pause_before_switchover called with the BQL locked - * Returns: 0 on success + * @migration_switchover_start: Start VM switchover procedure + * + * @s: The migration state object pointer + * + * Prepares for the switchover, depending on "pause-before-switchover" + * capability. + * + * If cap set, state machine goes like: + * [postcopy-]active -> pre-switchover -> device + * + * If cap not set: + * [postcopy-]active -> device + * + * Returns: true on success, false on interruptions. */ -static int migration_maybe_pause(MigrationState *s, int new_state) +static bool migration_switchover_start(MigrationState *s) { + /* Concurrent cancellation? Quit */ + if (s->state == MIGRATION_STATUS_CANCELLING) { + return false; + } + + /* + * No matter precopy or postcopy, since we still hold BQL it must not + * change concurrently to CANCELLING, so it must be either ACTIVE or + * POSTCOPY_ACTIVE. + */ + assert(migration_is_active()); + + /* If the pre stage not requested, directly switch to DEVICE */ if (!migrate_pause_before_switchover()) { - return 0; + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_DEVICE); + return true; } /* Since leaving this state is not atomic with posting the semaphore @@ -2709,23 +2731,22 @@ static int migration_maybe_pause(MigrationState *s, int new_state) /* This block intentionally left blank */ } + /* Update [POSTCOPY_]ACTIVE to PRE_SWITCHOVER */ + migrate_set_state(&s->state, s->state, MIGRATION_STATUS_PRE_SWITCHOVER); + bql_unlock(); + + qemu_sem_wait(&s->pause_sem); + + bql_lock(); /* - * If the migration is cancelled when it is in the completion phase, - * the migration state is set to MIGRATION_STATUS_CANCELLING. - * So we don't need to wait a semaphore, otherwise we would always - * wait for the 'pause_sem' semaphore. + * After BQL released and retaken, the state can be CANCELLING if it + * happend during sem_wait().. Only change the state if it's still + * pre-switchover. */ - if (s->state != MIGRATION_STATUS_CANCELLING) { - migrate_set_state(&s->state, s->state, - MIGRATION_STATUS_PRE_SWITCHOVER); - bql_unlock(); - qemu_sem_wait(&s->pause_sem); - bql_lock(); - migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, - new_state); - } + migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER, + MIGRATION_STATUS_DEVICE); - return s->state == new_state ? 0 : -EINVAL; + return s->state == MIGRATION_STATUS_DEVICE; } static int migration_completion_precopy(MigrationState *s) @@ -2741,8 +2762,7 @@ static int migration_completion_precopy(MigrationState *s) } } - ret = migration_maybe_pause(s, MIGRATION_STATUS_DEVICE); - if (ret < 0) { + if (!migration_switchover_start(s)) { goto out_unlock; } diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c index 5c0fa1f7c5..28a0901a0a 100644 --- a/tests/qtest/libqos/libqos.c +++ b/tests/qtest/libqos/libqos.c @@ -117,13 +117,14 @@ void migrate(QOSState *from, QOSState *to, const char *uri) g_assert(qdict_haskey(sub, "status")); st = qdict_get_str(sub, "status"); - /* "setup", "active", "completed", "failed", "cancelled" */ + /* "setup", "active", "device", "completed", "failed", "cancelled" */ if (strcmp(st, "completed") == 0) { qobject_unref(rsp); break; } if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0) + || (strcmp(st, "device") == 0) || (strcmp(st, "wait-unplug") == 0)) { qobject_unref(rsp); g_usleep(5000); diff --git a/tests/qemu-iotests/194.out b/tests/qemu-iotests/194.out index 376ed1d2e6..6940e809cd 100644 --- a/tests/qemu-iotests/194.out +++ b/tests/qemu-iotests/194.out @@ -14,6 +14,7 @@ Starting migration... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} Gracefully ending the `drive-mirror` job on source... {"return": {}} diff --git a/tests/qemu-iotests/203.out b/tests/qemu-iotests/203.out index 9d4abba8c5..8e58705e51 100644 --- a/tests/qemu-iotests/203.out +++ b/tests/qemu-iotests/203.out @@ -8,4 +8,5 @@ Starting migration... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} diff --git a/tests/qemu-iotests/234.out b/tests/qemu-iotests/234.out index ac8b64350c..be3e138b58 100644 --- a/tests/qemu-iotests/234.out +++ b/tests/qemu-iotests/234.out @@ -10,6 +10,7 @@ Starting migration to B... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} @@ -27,6 +28,7 @@ Starting migration back to A... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} diff --git a/tests/qemu-iotests/262.out b/tests/qemu-iotests/262.out index b8a2d3598d..bd7706b84b 100644 --- a/tests/qemu-iotests/262.out +++ b/tests/qemu-iotests/262.out @@ -8,6 +8,7 @@ Starting migration to B... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} diff --git a/tests/qemu-iotests/280.out b/tests/qemu-iotests/280.out index 546dbb4a68..37411144ca 100644 --- a/tests/qemu-iotests/280.out +++ b/tests/qemu-iotests/280.out @@ -7,6 +7,7 @@ Enabling migration QMP events on VM... {"return": {}} {"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "device"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} {"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} VM is now stopped: From patchwork Tue Jan 14 23:07:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36902E77188 for ; Tue, 14 Jan 2025 23:09:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1V-00023a-C3; Tue, 14 Jan 2025 18:08:37 -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 1tXq1K-00021k-VN for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:28 -0500 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 1tXq1G-0004DC-RJ for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896101; 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=Uw97LMM4hh1MOntWweq85MDlCjOv/z8693OvKaqOQvo=; b=ZWUEKz+FsbA8xTPBFmAP0MTUHWPNdPFIc1VXE73AJ0FJlH7FaCoWJdOVEKWFhfbIQ2IpS8 JZjy5VRs4qhSIhmrLpha2wkmmL/NVb3Ys/XdykKJa7d8VOaD+aQHXTzl+AKuotjfF+hy69 jJRSSVxaNV6d2X89Rn3WZwlncZ+eFwo= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-TZdi32LlNHK4YGZICVlYVQ-1; Tue, 14 Jan 2025 18:08:18 -0500 X-MC-Unique: TZdi32LlNHK4YGZICVlYVQ-1 X-Mimecast-MFC-AGG-ID: TZdi32LlNHK4YGZICVlYVQ Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4678b42cbfeso122244701cf.3 for ; Tue, 14 Jan 2025 15:08:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896096; x=1737500896; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uw97LMM4hh1MOntWweq85MDlCjOv/z8693OvKaqOQvo=; b=Gv8ws/KRZEKpSTKkEbfCJYn9cTNUbUrraOqUmqCO0Rug5ooVX5GAcWJTstU8CB7ovn NUiOJzdfjq1bDSEKfcb4Tjy6O4AgO7L12tLBjiFLjbfljcunWa0Vbi9ORXPb0avGIM4Z Le/FX5kQAhXYEin6zjSve32vXu814UMUZdZJ66m9HbZxbMKYHI/T3o5zqpvgHM7hliA8 aUdw2IWlNmEbtBoHFmX18Thb33K6n7yjmQ08eWoLv6L7pDtGzSMEJ+RC8+edobL/dyI3 M9qnJF7oJZD5gSvjCcuTQA8sF5kMuQoc18fibYhqj7cJBdwKNguhk25ANSrYnuhjCjo7 WwBA== X-Gm-Message-State: AOJu0Yxxl9/JwvTQNOc0lu/LyeGQV+O7UKBgAFfS94AY+6H25gYK8EUO iNsOOtGPk7nZFsG6w//t+q6/Rfrs9+j3zIh6lDedIyozKOf9fhJDIs3tC8qpeVFGsKj567uGvSU 7JML/TZ/FH73N9AUNOCYFVnzFkKqZBzhA3GSm3cAMVrE5zNsY3NrFe84O+NBdcnHOhkFt9Pjs87 5bt8Ml0vImRdWK1ngSzUyh7WpiNSk6WHswug== X-Gm-Gg: ASbGncs3YuDH+wztNiEQa4L841RIeiBAP/TSQ3ZGeyLSJ4SRno0PYTTPA7Kw9AQImam HfJBU51GjNZzR8rTFexUIL3ug3OPhXaZZV5M5w5mVsC/VNKGGxdfpc9b7sP1wzCXnIwNNJsBlM5 DvGlEEmKM9ucutm86n87RZdKjuXtOGLcjiqJ4ufGCoSoesAaWePzpPNQxlZPMtI08akkAei0XJ/ IjoKId92FEryn4PJtmbeZjpUZPoRTICyGJF/yTEjF+ygxoM4ZYqzOZI8nlGH+BoxDt4DOwfuM++ N1iA8MhnHCWE/jnUZW8cWFJzzYM+hws4 X-Received: by 2002:ac8:5852:0:b0:467:5eaf:7d1f with SMTP id d75a77b69052e-46c710a63ebmr451181351cf.50.1736896096257; Tue, 14 Jan 2025 15:08:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTUAFzoNp7Mz4AuWe94I+cTCZXdUgKKsBUdzu3bpygRta5pCXnW5eMIugh16bHEis9jBvH4A== X-Received: by 2002:ac8:5852:0:b0:467:5eaf:7d1f with SMTP id d75a77b69052e-46c710a63ebmr451180961cf.50.1736896095882; Tue, 14 Jan 2025 15:08:15 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:14 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 15/16] migration: Merge precopy/postcopy on switchover start Date: Tue, 14 Jan 2025 18:07:45 -0500 Message-ID: <20250114230746.3268797-16-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now after all the cleanups, finally we can merge the switchover startup phase into one single function for precopy/postcopy. Signed-off-by: Peter Xu --- migration/migration.c | 62 ++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 2a95081b6c..f6694e7e94 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -102,7 +102,7 @@ static MigrationIncomingState *current_incoming; static GSList *migration_blockers[MIG_MODE__MAX]; static bool migration_object_check(MigrationState *ms, Error **errp); -static bool migration_switchover_start(MigrationState *s); +static bool migration_switchover_start(MigrationState *s, Error **errp); static void migrate_fd_cancel(MigrationState *s); static bool close_return_path_on_source(MigrationState *s); static void migration_completion_end(MigrationState *s); @@ -2540,21 +2540,10 @@ static int postcopy_start(MigrationState *ms, Error **errp) goto fail; } - if (!migration_switchover_start(ms)) { - error_setg(errp, "migration_switchover_start() failed"); + if (!migration_switchover_start(ms, errp)) { goto fail; } - if (!migration_block_inactivate()) { - error_setg(errp, "%s: Failed in bdrv_inactivate_all()", __func__); - goto fail; - } - - /* Switchover phase, switch to unlimited */ - migration_rate_set(RATE_LIMIT_DISABLED); - - precopy_notify_complete(); - /* * Cause any non-postcopiable, but iterative devices to * send out their final data. @@ -2686,7 +2675,7 @@ fail: } /** - * @migration_switchover_start: Start VM switchover procedure + * @migration_switchover_prepare: Start VM switchover procedure * * @s: The migration state object pointer * @@ -2701,7 +2690,7 @@ fail: * * Returns: true on success, false on interruptions. */ -static bool migration_switchover_start(MigrationState *s) +static bool migration_switchover_prepare(MigrationState *s) { /* Concurrent cancellation? Quit */ if (s->state == MIGRATION_STATUS_CANCELLING) { @@ -2749,21 +2738,13 @@ static bool migration_switchover_start(MigrationState *s) return s->state == MIGRATION_STATUS_DEVICE; } -static int migration_completion_precopy(MigrationState *s) +static bool migration_switchover_start(MigrationState *s, Error **errp) { - int ret; - - bql_lock(); - - if (!migrate_mode_is_cpr(s)) { - ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); - if (ret < 0) { - goto out_unlock; - } - } + ERRP_GUARD(); - if (!migration_switchover_start(s)) { - goto out_unlock; + if (!migration_switchover_prepare(s)) { + error_setg(errp, "Switchover is interrupted"); + return false; } /* Inactivate disks except in COLO */ @@ -2773,8 +2754,8 @@ static int migration_completion_precopy(MigrationState *s) * bdrv_activate_all() on the other end won't fail. */ if (!migration_block_inactivate()) { - ret = -EFAULT; - goto out_unlock; + error_setg(errp, "Block inactivate failed during switchover"); + return false; } } @@ -2782,6 +2763,27 @@ static int migration_completion_precopy(MigrationState *s) precopy_notify_complete(); + return true; +} + +static int migration_completion_precopy(MigrationState *s) +{ + int ret; + + bql_lock(); + + if (!migrate_mode_is_cpr(s)) { + ret = migration_stop_vm(s, RUN_STATE_FINISH_MIGRATE); + if (ret < 0) { + goto out_unlock; + } + } + + if (!migration_switchover_start(s, NULL)) { + ret = -EFAULT; + goto out_unlock; + } + ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false); out_unlock: bql_unlock(); From patchwork Tue Jan 14 23:07:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13939662 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02348E77188 for ; Tue, 14 Jan 2025 23:11:20 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tXq1e-00025e-Dy; Tue, 14 Jan 2025 18:08:46 -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 1tXq1K-00021j-V0 for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:28 -0500 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 1tXq1G-0004DF-SC for qemu-devel@nongnu.org; Tue, 14 Jan 2025 18:08:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736896101; 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=jSPuM/xQN55RkRx/S3nnX/mnwXvxno14BL0e7ID8OVM=; b=dLSiulXxPPKrEG8SOxq8+8sJYfDqKK0cQu3ArJ+LFkWKWlwzGajNM5KR5RJ0l/ryKVwEim UVCqHFUE65FShHKrInDM05IuxFRkbo51vMkIHmTeipnqjuG24d5fYrb+DUenYFj9Q1kr9b PiGsrBYqv711GemZXPZU4eUiWTgeupo= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-464-jxr_NqIqOjqv-opjs7SioQ-1; Tue, 14 Jan 2025 18:08:19 -0500 X-MC-Unique: jxr_NqIqOjqv-opjs7SioQ-1 X-Mimecast-MFC-AGG-ID: jxr_NqIqOjqv-opjs7SioQ Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-46790c5b1a5so151524391cf.2 for ; Tue, 14 Jan 2025 15:08:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736896098; x=1737500898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jSPuM/xQN55RkRx/S3nnX/mnwXvxno14BL0e7ID8OVM=; b=Zgoz3ouT8satE7Hldw5JUAv+j4RpEdkTp6UReYA99GlHPm8jBLffct5qcWinqm4fkW RZFsibEpwarfciAkCp33HeoIYFIH02s/dWxsC8/35Rg1q3dpVm2VPk/sxjVifjL7JyER HeNeHxSNJtNDv5sAAOq6YYvrR7xZIwPe6/f6l0WKaq+VX4ruSMkKmwSwpQfZcKHD0/3t be0CsxqYQaBcNX56JXH7RylaPC4wj+/urziUU6U7GZavyAxACLIB4G8GRk6bDqiePQPE 9iXYUOPwxi9Tkk1cX+2hbfx0UswYhvGVOG40t1wNvLOPwdmjiZdcufFB6EetyxLJkjmP Pn4A== X-Gm-Message-State: AOJu0YxT7ZSA8h9r5nkzG0+DV0ZajNUy5YDgKhMUnkOTCHKA0xje/EAE ep1iEYfVgSTDcPgvqqQbLfd6FcRal0Vx0gI3newLmsWz/Hcvx8uap1e5bVC6juoPpaES8zVR/ii 2KhxCIYFqVhoP2DPvgZuipL2Wmca3gI7AfW2BppHu82jyOwd+UiKdkbg9RUs88g+KGT3AQ7+FI8 UMsGhaMtRG3j+RTHUzVdjsbvCu3qtlnwaciA== X-Gm-Gg: ASbGncvHKLs43OfpKTfb+WtUoWPTwCTRgx/lb3SxTbVwEtPf2eUcFfnTlPZt+46atYR 92fNZipMgbEJ7iE3Wwpi+h4b4WUK30rMSl1GddariQlp91QK+tkh7QFQPRcdmAtKTYq2q5HaetV ZDBy6ZQR0HbWav1/fv9KnocnUJaTOARIDvQkMrYoNZto33YcNFjd5S5AcUy5vdWppe5A0+XsyIR sE9RXt4aFEbq4d2mlLkE6TDb4/9PvCmFn+3HDKr1eaClG3AgaZvtKPpSTHRSommtOuqyhey4hH7 HdzJNoTp5MShXFKEbDCNH/9BG2d+jNpF X-Received: by 2002:a05:622a:1a0d:b0:467:525b:e540 with SMTP id d75a77b69052e-46c70fd31d9mr387709011cf.8.1736896097963; Tue, 14 Jan 2025 15:08:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHHW69C9d68DiM1NK3PXF02OfpzQRaH4AH0+V4LHEgLBBw+tb9CCIn1FEGWOQsCF6uPCePgw== X-Received: by 2002:a05:622a:1a0d:b0:467:525b:e540 with SMTP id d75a77b69052e-46c70fd31d9mr387708661cf.8.1736896097537; Tue, 14 Jan 2025 15:08:17 -0800 (PST) Received: from x1n.redhat.com (pool-99-254-114-190.cpe.net.cable.rogers.com. [99.254.114.190]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-46c873cd1b0sm59268971cf.49.2025.01.14.15.08.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 15:08:16 -0800 (PST) From: Peter Xu To: qemu-devel@nongnu.org Cc: peterx@redhat.com, Juraj Marcin , Julia Suvorova , Prasad Pandit , Fabiano Rosas Subject: [PATCH 16/16] migration: Trivial cleanup on JSON writer of vmstate_save() Date: Tue, 14 Jan 2025 18:07:46 -0500 Message-ID: <20250114230746.3268797-17-peterx@redhat.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250114230746.3268797-1-peterx@redhat.com> References: <20250114230746.3268797-1-peterx@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -39 X-Spam_score: -4.0 X-Spam_bar: ---- X-Spam_report: (-4.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.063, 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=-1.794, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Two small cleanups in the same section of vmstate_save(): - Check vmdesc before the "mixed null/non-null data in array" logic, to be crystal clear that it's only about the JSON writer, not the vmstate on its own in the migration stream. - Since we have is_null variable now, use that to replace a check. Signed-off-by: Peter Xu --- migration/vmstate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/vmstate.c b/migration/vmstate.c index 82bd005a83..047a52af89 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -459,6 +459,8 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, } /* + * This logic only matters when dumping VM Desc. + * * Due to the fake nullptr handling above, if there's mixed * null/non-null data, it doesn't make sense to emit a * compressed array representation spanning the entire array @@ -466,7 +468,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, * vs. nullptr). Search ahead for the next null/non-null element * and start a new compressed array if found. */ - if (field->flags & VMS_ARRAY_OF_POINTER && + if (vmdesc && (field->flags & VMS_ARRAY_OF_POINTER) && is_null != is_prev_null) { is_prev_null = is_null; @@ -504,7 +506,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, written_bytes); /* If we used a fake temp field.. free it now */ - if (inner_field != field) { + if (is_null) { g_clear_pointer((gpointer *)&inner_field, g_free); }