qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Xu" <peterx@redhat.com>, "Fabiano Rosas" <farosas@suse.de>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"Avihai Horon" <avihaih@nvidia.com>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Anthony Perard" <anthony.perard@citrix.com>,
	"Paul Durrant" <paul@xen.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Hyman Huang" <yong.huang@smartx.com>
Subject: [PATCH v3 15/26] memory: Add Error** argument to the global_dirty_log routines
Date: Mon,  4 Mar 2024 13:28:33 +0100	[thread overview]
Message-ID: <20240304122844.1888308-16-clg@redhat.com> (raw)
In-Reply-To: <20240304122844.1888308-1-clg@redhat.com>

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 <sstabellini@kernel.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Paul Durrant <paul@xen.org>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Hyman Huang <yong.huang@smartx.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/exec/memory.h | 10 ++++++++--
 hw/i386/xen/xen-hvm.c |  4 ++--
 migration/dirtyrate.c | 21 +++++++++++++++++----
 migration/ram.c       | 34 ++++++++++++++++++++++++++++++----
 system/memory.c       | 30 ++++++++++++------------------
 5 files changed, 69 insertions(+), 30 deletions(-)

diff --git a/include/exec/memory.h b/include/exec/memory.h
index 4bc146c5ebdd377cd14a4e462f32cc945db5a0a8..8b019465ab13ce85c03075c80865a0865ea1feed 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2576,15 +2576,21 @@ void memory_listener_unregister(MemoryListener *listener);
  * 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);
 
 /**
  * memory_global_dirty_log_stop: end dirty logging for all regions
  *
  * @flags: purpose of stopping 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_stop(unsigned int flags);
+bool memory_global_dirty_log_stop(unsigned int flags, Error **errp);
 
 void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabled);
 
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index 925a207b494b4eed52d5f360b554f18ac8a9806d..286269b47572d90e57df5ff44835bb5f8e16c7ad 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -655,9 +655,9 @@ 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);
+        memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION, errp);
     }
 }
 
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index 1d2e85746fb7b10eb7f149976970f9a92125af8a..34f6d803ff5f4e6ccf2e06aaaed65a336c4be469 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -90,11 +90,17 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages,
 
 void global_dirty_log_change(unsigned int flag, bool start)
 {
+    Error *local_err = NULL;
+    bool ret;
+
     bql_lock();
     if (start) {
-        memory_global_dirty_log_start(flag);
+        ret = memory_global_dirty_log_start(flag, &local_err);
     } else {
-        memory_global_dirty_log_stop(flag);
+        ret = memory_global_dirty_log_stop(flag, &local_err);
+    }
+    if (!ret) {
+        error_report_err(local_err);
     }
     bql_unlock();
 }
@@ -106,10 +112,14 @@ void global_dirty_log_change(unsigned int flag, bool start)
  */
 static void global_dirty_log_sync(unsigned int flag, bool one_shot)
 {
+    Error *local_err = NULL;
+
     bql_lock();
     memory_global_dirty_log_sync(false);
     if (one_shot) {
-        memory_global_dirty_log_stop(flag);
+        if (!memory_global_dirty_log_stop(flag, &local_err)) {
+            error_report_err(local_err);
+        }
     }
     bql_unlock();
 }
@@ -608,9 +618,12 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
 {
     int64_t start_time;
     DirtyPageRecord dirty_pages;
+    Error *local_err = NULL;
 
     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);
+    }
 
     /*
      * 1'round of log sync may return all 1 bits with
diff --git a/migration/ram.c b/migration/ram.c
index 20c6ad9e759b2b8ec7ae26b7ca72d5cbd20d481f..3d9c08cfae8a59031a7c1b3c70721c2a90daceba 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2390,6 +2390,7 @@ static void ram_save_cleanup(void *opaque)
 {
     RAMState **rsp = opaque;
     RAMBlock *block;
+    Error *local_err = NULL;
 
     /* We don't use dirty log with background snapshots */
     if (!migrate_background_snapshot()) {
@@ -2402,7 +2403,10 @@ static void ram_save_cleanup(void *opaque)
              * memory_global_dirty_log_stop will assert that
              * memory_global_dirty_log_start/stop used in pairs
              */
-            memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION);
+            if (!memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION,
+                                              &local_err)) {
+                error_report_err(local_err);
+            }
         }
     }
 
@@ -2799,18 +2803,31 @@ static void migration_bitmap_clear_discarded_pages(RAMState *rs)
 
 static void ram_init_bitmaps(RAMState *rs)
 {
+    Error *local_err = NULL;
+    bool ret = true;
+
     qemu_mutex_lock_ramlist();
 
     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 = 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();
 
+    if (!ret) {
+        return;
+    }
+
     /*
      * After an eventual first bitmap sync, fixup the initial bitmap
      * containing all 1s to exclude any discarded pages from migration.
@@ -3459,6 +3476,8 @@ int colo_init_ram_cache(void)
 void colo_incoming_start_dirty_log(void)
 {
     RAMBlock *block = NULL;
+    Error *local_err = NULL;
+
     /* For memory_global_dirty_log_start below. */
     bql_lock();
     qemu_mutex_lock_ramlist();
@@ -3470,7 +3489,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 = 0;
     qemu_mutex_unlock_ramlist();
@@ -3481,8 +3503,12 @@ void colo_incoming_start_dirty_log(void)
 void colo_release_ram_cache(void)
 {
     RAMBlock *block;
+    Error *local_err = NULL;
+
+    if (!memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION, &local_err)) {
+        error_report_err(local_err);
+    }
 
-    memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION);
     RAMBLOCK_FOREACH_NOT_IGNORED(block) {
         g_free(block->bmap);
         block->bmap = NULL;
diff --git a/system/memory.c b/system/memory.c
index af06157ead5b1272548e87f79ab9fb3036055328..48aed0f8ece1c731849636c442b8ab8e5d7ff6a5 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2949,25 +2949,24 @@ static unsigned int postponed_stop_flags;
 static VMChangeStateEntry *vmstate_change;
 static bool memory_global_dirty_log_stop_postponed_run(Error **errp);
 
-void memory_global_dirty_log_start(unsigned int flags)
+bool memory_global_dirty_log_start(unsigned int flags, Error **errp)
 {
+    ERRP_GUARD();
     unsigned int old_flags;
-    Error *local_err = NULL;
 
     assert(flags && !(flags & (~GLOBAL_DIRTY_MASK)));
 
     if (vmstate_change) {
         /* If there is postponed stop(), operate on it first */
         postponed_stop_flags &= ~flags;
-        if (!memory_global_dirty_log_stop_postponed_run(&local_err)) {
-            error_report_err(local_err);
-            return;
+        if (!memory_global_dirty_log_stop_postponed_run(errp)) {
+            return false;
         }
     }
 
     flags &= ~global_dirty_tracking;
     if (!flags) {
-        return;
+        return true;
     }
 
     old_flags = global_dirty_tracking;
@@ -2975,16 +2974,15 @@ void memory_global_dirty_log_start(unsigned int flags)
     trace_global_dirty_changed(global_dirty_tracking);
 
     if (!old_flags) {
-        MEMORY_LISTENER_CALL_LOG_GLOBAL(log_global_start, Forward,
-                                        &local_err);
-        if (local_err) {
-            error_report_err(local_err);
-            return;
+        MEMORY_LISTENER_CALL_LOG_GLOBAL(log_global_start, Forward, errp);
+        if (*errp) {
+            return false;
         }
         memory_region_transaction_begin();
         memory_region_update_pending = true;
         memory_region_transaction_commit();
     }
+    return true;
 }
 
 static bool memory_global_dirty_log_do_stop(unsigned int flags, Error **errp)
@@ -3040,10 +3038,8 @@ static void memory_vm_change_state_handler(void *opaque, bool running,
     }
 }
 
-void memory_global_dirty_log_stop(unsigned int flags)
+bool memory_global_dirty_log_stop(unsigned int flags, Error **errp)
 {
-    Error *local_err = NULL;
-
     if (!runstate_is_running()) {
         /* Postpone the dirty log stop, e.g., to when VM starts again */
         if (vmstate_change) {
@@ -3054,12 +3050,10 @@ void memory_global_dirty_log_stop(unsigned int flags)
             vmstate_change = qemu_add_vm_change_state_handler(
                 memory_vm_change_state_handler, NULL);
         }
-        return;
+        return true;
     }
 
-    if (!memory_global_dirty_log_do_stop(flags, &local_err)) {
-        error_report_err(local_err);
-    }
+    return memory_global_dirty_log_do_stop(flags, errp);
 }
 
 static void listener_add_address_space(MemoryListener *listener,
-- 
2.44.0



  parent reply	other threads:[~2024-03-04 12:37 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 12:28 [PATCH v3 00/26] migration: Improve error reporting Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 01/26] s390/stattrib: Add Error** argument to set_migrationmode() handler Cédric Le Goater
2024-03-04 20:49   ` Fabiano Rosas
2024-03-05  7:12     ` Cédric Le Goater
2024-03-05 14:54   ` Avihai Horon
2024-03-04 12:28 ` [PATCH v3 02/26] vfio: Always report an error in vfio_save_setup() Cédric Le Goater
2024-03-04 20:51   ` Fabiano Rosas
2024-03-06  9:56   ` Avihai Horon
2024-03-06 10:16     ` Avihai Horon
2024-03-06 10:51       ` Cédric Le Goater
2024-03-06 10:49     ` Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 03/26] migration: Always report an error in block_save_setup() Cédric Le Goater
2024-03-04 21:04   ` Fabiano Rosas
2024-03-05  8:23     ` Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 04/26] migration: Always report an error in ram_save_setup() Cédric Le Goater
2024-03-04 21:30   ` Fabiano Rosas
2024-03-05  8:52     ` Cédric Le Goater
2024-03-05  5:29   ` Prasad Pandit
2024-03-05  8:53     ` Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 05/26] migration: Add Error** argument to vmstate_save() Cédric Le Goater
2024-03-05  7:44   ` Prasad Pandit
2024-03-04 12:28 ` [PATCH v3 06/26] migration: Report error when shutdown fails Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 07/26] migration: Remove SaveStateHandler and LoadStateHandler typedefs Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 08/26] migration: Add documentation for SaveVMHandlers Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 09/26] migration: Do not call PRECOPY_NOTIFY_SETUP notifiers in case of error Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 10/26] migration: Move cleanup after after error reporting in qemu_savevm_state_setup() Cédric Le Goater
2024-03-05  3:32   ` Peter Xu
2024-03-05  7:57     ` Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 11/26] migration: Add Error** argument to qemu_savevm_state_setup() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 12/26] migration: Add Error** argument to .save_setup() handler Cédric Le Goater
2024-03-05  8:54   ` Thomas Huth
2024-03-04 12:28 ` [PATCH v3 13/26] migration: Add Error** argument to .load_setup() handler Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 14/26] memory: Add Error** argument to .log_global*() handlers Cédric Le Goater
2024-03-05  7:57   ` Peter Xu
2024-03-05 14:25     ` Cédric Le Goater
2024-03-04 12:28 ` Cédric Le Goater [this message]
2024-03-05  1:58   ` [PATCH v3 15/26] memory: Add Error** argument to the global_dirty_log routines Yong Huang
2024-03-04 12:28 ` [PATCH v3 16/26] migration: Modify ram_init_bitmaps() to report dirty tracking errors Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 17/26] vfio: Add Error** argument to .set_dirty_page_tracking() handler Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 18/26] vfio: Add Error** argument to vfio_devices_dma_logging_start() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 19/26] vfio: Add Error** argument to vfio_devices_dma_logging_stop() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 20/26] vfio: Use new Error** argument in vfio_save_setup() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 21/26] vfio: Add Error** argument to .vfio_save_config() handler Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 22/26] vfio: Reverse test on vfio_get_dirty_bitmap() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 23/26] memory: Add Error** argument to memory_get_xlat_addr() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 24/26] vfio: Add Error** argument to .get_dirty_bitmap() handler Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 25/26] vfio: Also trace event failures in vfio_save_complete_precopy() Cédric Le Goater
2024-03-04 12:28 ` [PATCH v3 26/26] vfio: Extend vfio_set_migration_error() with Error* argument Cédric Le Goater
2024-03-05  8:06 ` [PATCH v3 00/26] migration: Improve error reporting Peter Xu
2024-03-05  8:30   ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240304122844.1888308-16-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=anthony.perard@citrix.com \
    --cc=armbru@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=david@redhat.com \
    --cc=farosas@suse.de \
    --cc=mst@redhat.com \
    --cc=paul@xen.org \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sstabellini@kernel.org \
    --cc=yong.huang@smartx.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).