From nobody Tue Nov 26 09:46:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709732191109548.517084651175; Wed, 6 Mar 2024 05:36:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhrR9-0000hE-2w; Wed, 06 Mar 2024 08:35:59 -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 1rhrR7-0000cZ-3M for qemu-devel@nongnu.org; Wed, 06 Mar 2024 08:35:57 -0500 Received: from mail.ozlabs.org ([2404:9400:2221:ea00::3] helo=gandalf.ozlabs.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhrR4-0006B3-Ot for qemu-devel@nongnu.org; Wed, 06 Mar 2024 08:35:56 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TqYNS4q0Sz4wyt; Thu, 7 Mar 2024 00:35:52 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4TqYNM0kzsz4wcF; Thu, 7 Mar 2024 00:35:46 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Peter Xu , Fabiano Rosas , Alex Williamson , Avihai Horon , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Prasad Pandit , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Stefano Stabellini , Anthony Perard , Paul Durrant , "Michael S. Tsirkin" , Paolo Bonzini , David Hildenbrand , Hyman Huang Subject: [PATCH v4 14/25] memory: Add Error** argument to the global_dirty_log routines Date: Wed, 6 Mar 2024 14:34:29 +0100 Message-ID: <20240306133441.2351700-15-clg@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240306133441.2351700-1-clg@redhat.com> References: <20240306133441.2351700-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2404:9400:2221:ea00::3; envelope-from=SRS0=yBjJ=KM=redhat.com=clg@ozlabs.org; helo=gandalf.ozlabs.org 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, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1709732193391100007 Now that the log_global*() handlers take an Error** parameter and return a bool, do the same for memory_global_dirty_log_start() and memory_global_dirty_log_stop(). The error is reported in the callers for now and it will be propagated in the call stack in the next changes. To be noted a functional change in ram_init_bitmaps(), if the dirty pages logger fails to start, there is no need to synchronize the dirty pages bitmaps. colo_incoming_start_dirty_log() could be modified in a similar way. Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paul Durrant Cc: "Michael S. Tsirkin" Cc: Paolo Bonzini Cc: David Hildenbrand Cc: Hyman Huang Reviewed-by: Hyman Huang Signed-off-by: C=C3=A9dric Le Goater --- Changes in v4: - Dropped log_global_stop() and log_global_sync() changes =20 include/exec/memory.h | 5 ++++- hw/i386/xen/xen-hvm.c | 2 +- migration/dirtyrate.c | 13 +++++++++++-- migration/ram.c | 22 ++++++++++++++++++++-- system/memory.c | 11 +++++------ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 5555567bc4c9fdb53e8f63487f1400980275687d..c129ee6db7162504bd72d4cfc69= b5affb2cd87e8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2570,8 +2570,11 @@ void memory_listener_unregister(MemoryListener *list= ener); * memory_global_dirty_log_start: begin dirty logging for all regions * * @flags: purpose of starting dirty log, migration or dirty rate + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. */ -void memory_global_dirty_log_start(unsigned int flags); +bool memory_global_dirty_log_start(unsigned int flags, Error **errp); =20 /** * memory_global_dirty_log_stop: end dirty logging for all regions diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 0608ca99f5166fd6379ee674442484e805eff9c0..57cb7df50788a6c31eff68c95e8= eaa856fdebede 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -654,7 +654,7 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr= _t length) void qmp_xen_set_global_dirty_log(bool enable, Error **errp) { if (enable) { - memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); + memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, errp); } else { memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); } diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 1d2e85746fb7b10eb7f149976970f9a92125af8a..d02d70b7b4b86a29d4d5540ded4= 16543536d8f98 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -90,9 +90,15 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord di= rty_pages, =20 void global_dirty_log_change(unsigned int flag, bool start) { + Error *local_err =3D NULL; + bool ret; + bql_lock(); if (start) { - memory_global_dirty_log_start(flag); + ret =3D memory_global_dirty_log_start(flag, &local_err); + if (!ret) { + error_report_err(local_err); + } } else { memory_global_dirty_log_stop(flag); } @@ -608,9 +614,12 @@ static void calculate_dirtyrate_dirty_bitmap(struct Di= rtyRateConfig config) { int64_t start_time; DirtyPageRecord dirty_pages; + Error *local_err =3D NULL; =20 bql_lock(); - memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE); + if (!memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE, &local_err= )) { + error_report_err(local_err); + } =20 /* * 1'round of log sync may return all 1 bits with diff --git a/migration/ram.c b/migration/ram.c index c5149b7d717aefad7f590422af0ea4a40e7507be..397b4c0f218a66d194e44f9c5f9= fe8e9885c48b6 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2836,18 +2836,31 @@ static void migration_bitmap_clear_discarded_pages(= RAMState *rs) =20 static void ram_init_bitmaps(RAMState *rs) { + Error *local_err =3D NULL; + bool ret =3D true; + qemu_mutex_lock_ramlist(); =20 WITH_RCU_READ_LOCK_GUARD() { ram_list_init_bitmaps(); /* We don't use dirty log with background snapshots */ if (!migrate_background_snapshot()) { - memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); + ret =3D memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, + &local_err); + if (!ret) { + error_report_err(local_err); + goto out_unlock; + } migration_bitmap_sync_precopy(rs, false); } } +out_unlock: qemu_mutex_unlock_ramlist(); =20 + if (!ret) { + return; + } + /* * After an eventual first bitmap sync, fixup the initial bitmap * containing all 1s to exclude any discarded pages from migration. @@ -3631,6 +3644,8 @@ int colo_init_ram_cache(void) void colo_incoming_start_dirty_log(void) { RAMBlock *block =3D NULL; + Error *local_err =3D NULL; + /* For memory_global_dirty_log_start below. */ bql_lock(); qemu_mutex_lock_ramlist(); @@ -3642,7 +3657,10 @@ void colo_incoming_start_dirty_log(void) /* Discard this dirty bitmap record */ bitmap_zero(block->bmap, block->max_length >> TARGET_PAGE_BITS= ); } - memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); + if (!memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, + &local_err)) { + error_report_err(local_err); + } } ram_state->migration_dirty_pages =3D 0; qemu_mutex_unlock_ramlist(); diff --git a/system/memory.c b/system/memory.c index 3600e716149407c10a1f6bf8f0a81c2611cf15ba..cbc098216b789f50460f1d1bc7e= c122030693d9e 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2931,10 +2931,9 @@ static void memory_global_dirty_log_rollback(MemoryL= istener *listener, } } =20 -void memory_global_dirty_log_start(unsigned int flags) +bool memory_global_dirty_log_start(unsigned int flags, Error **errp) { unsigned int old_flags; - Error *local_err =3D NULL; =20 assert(flags && !(flags & (~GLOBAL_DIRTY_MASK))); =20 @@ -2946,7 +2945,7 @@ void memory_global_dirty_log_start(unsigned int flags) =20 flags &=3D ~global_dirty_tracking; if (!flags) { - return; + return true; } =20 old_flags =3D global_dirty_tracking; @@ -2959,7 +2958,7 @@ void memory_global_dirty_log_start(unsigned int flags) =20 QTAILQ_FOREACH(listener, &memory_listeners, link) { if (listener->log_global_start) { - ret =3D listener->log_global_start(listener, &local_err); + ret =3D listener->log_global_start(listener, errp); if (!ret) { break; } @@ -2969,14 +2968,14 @@ void memory_global_dirty_log_start(unsigned int fla= gs) if (!ret) { memory_global_dirty_log_rollback(QTAILQ_PREV(listener, link), flags); - error_report_err(local_err); - return; + return false; } =20 memory_region_transaction_begin(); memory_region_update_pending =3D true; memory_region_transaction_commit(); } + return true; } =20 static void memory_global_dirty_log_do_stop(unsigned int flags) --=20 2.44.0