From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org
Cc: peterx@redhat.com, "Prasad Pandit" <ppandit@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Fabiano Rosas" <farosas@suse.de>,
"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: [PULL 20/26] memory: Add Error** argument to the global_dirty_log routines
Date: Tue, 23 Apr 2024 18:38:07 -0400 [thread overview]
Message-ID: <20240423223813.3237060-21-peterx@redhat.com> (raw)
In-Reply-To: <20240423223813.3237060-1-peterx@redhat.com>
From: Cédric Le Goater <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>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Acked-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20240320064911.545001-12-clg@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
include/exec/memory.h | 5 ++++-
hw/i386/xen/xen-hvm.c | 2 +-
migration/dirtyrate.c | 13 +++++++++++--
migration/ram.c | 23 +++++++++++++++++++++--
system/memory.c | 11 +++++------
5 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 5555567bc4..c129ee6db7 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2570,8 +2570,11 @@ 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
diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c
index f6e9a1bc86..006d219ad5 100644
--- a/hw/i386/xen/xen-hvm.c
+++ b/hw/i386/xen/xen-hvm.c
@@ -669,7 +669,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 1d2e85746f..d02d70b7b4 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -90,9 +90,15 @@ 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);
+ 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 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 f0bd71438a..bade3e9281 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2862,18 +2862,32 @@ 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) {
+ ram_bitmaps_destroy();
+ return;
+ }
+
/*
* After an eventual first bitmap sync, fixup the initial bitmap
* containing all 1s to exclude any discarded pages from migration.
@@ -3665,6 +3679,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();
@@ -3676,7 +3692,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();
diff --git a/system/memory.c b/system/memory.c
index 86d6c33180..c02c1d4bed 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -2937,10 +2937,9 @@ err:
return false;
}
-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 = NULL;
assert(flags && !(flags & (~GLOBAL_DIRTY_MASK)));
@@ -2952,7 +2951,7 @@ void memory_global_dirty_log_start(unsigned int flags)
flags &= ~global_dirty_tracking;
if (!flags) {
- return;
+ return true;
}
old_flags = global_dirty_tracking;
@@ -2960,17 +2959,17 @@ void memory_global_dirty_log_start(unsigned int flags)
trace_global_dirty_changed(global_dirty_tracking);
if (!old_flags) {
- if (!memory_global_dirty_log_do_start(&local_err)) {
+ if (!memory_global_dirty_log_do_start(errp)) {
global_dirty_tracking &= ~flags;
trace_global_dirty_changed(global_dirty_tracking);
- error_report_err(local_err);
- return;
+ return false;
}
memory_region_transaction_begin();
memory_region_update_pending = true;
memory_region_transaction_commit();
}
+ return true;
}
static void memory_global_dirty_log_do_stop(unsigned int flags)
--
2.44.0
next prev parent reply other threads:[~2024-04-23 22:40 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 22:37 [PULL 00/26] Migration 20240423 patches Peter Xu
2024-04-23 22:37 ` [PULL 01/26] tests/qtest/migration: Add 'to' object into migrate_qmp() Peter Xu
2024-04-23 22:37 ` [PULL 02/26] tests/qtest/migration: Replace connect_uri and move migrate_get_socket_address inside migrate_qmp Peter Xu
2024-04-23 22:37 ` [PULL 03/26] tests/qtest/migration: Replace migrate_get_connect_uri inplace of migrate_get_socket_address Peter Xu
2024-04-23 22:37 ` [PULL 04/26] tests/qtest/migration: Add channels parameter in migrate_qmp_fail Peter Xu
2024-04-23 22:37 ` [PULL 05/26] tests/qtest/migration: Add migrate_set_ports into migrate_qmp to update migration port value Peter Xu
2024-04-23 22:37 ` [PULL 06/26] tests/qtest/migration: Add channels parameter in migrate_qmp Peter Xu
2024-04-23 22:37 ` [PULL 07/26] tests/qtest/migration: Add multifd_tcp_plain test using list of channels instead of uri Peter Xu
2024-04-23 22:37 ` [PULL 08/26] tests/qtest/migration: Add negative tests to validate migration QAPIs Peter Xu
2024-04-23 22:37 ` [PULL 09/26] tests/qtest/migration: Fix typo for vsock in SocketAddress_to_str Peter Xu
2024-04-23 22:37 ` [PULL 10/26] s390/stattrib: Add Error** argument to set_migrationmode() handler Peter Xu
2024-04-23 22:37 ` [PULL 11/26] vfio: Always report an error in vfio_save_setup() Peter Xu
2024-04-23 22:37 ` [PULL 12/26] migration: Always report an error in block_save_setup() Peter Xu
2024-04-23 22:38 ` [PULL 13/26] migration: Always report an error in ram_save_setup() Peter Xu
2024-04-23 22:38 ` [PULL 14/26] migration: Add Error** argument to vmstate_save() Peter Xu
2024-04-23 22:38 ` [PULL 15/26] migration: Add Error** argument to qemu_savevm_state_setup() Peter Xu
2024-04-23 22:38 ` [PULL 16/26] migration: Add Error** argument to .save_setup() handler Peter Xu
2024-04-23 22:38 ` [PULL 17/26] migration: Add Error** argument to .load_setup() handler Peter Xu
2024-04-23 22:38 ` [PULL 18/26] memory: Add Error** argument to .log_global_start() handler Peter Xu
2024-04-23 22:38 ` [PULL 19/26] migration: Introduce ram_bitmaps_destroy() Peter Xu
2024-04-23 22:38 ` Peter Xu [this message]
2024-04-23 22:38 ` [PULL 21/26] migration: Add Error** argument to ram_state_init() Peter Xu
2024-04-23 22:38 ` [PULL 22/26] migration: Add Error** argument to xbzrle_init() Peter Xu
2024-04-23 22:38 ` [PULL 23/26] migration: Modify ram_init_bitmaps() to report dirty tracking errors Peter Xu
2024-04-23 22:38 ` [PULL 24/26] migration: Add Error** argument to add_bitmaps_to_list() Peter Xu
2024-04-23 22:38 ` [PULL 25/26] migration/multifd: solve zero page causing multiple page faults Peter Xu
2024-04-23 22:38 ` [PULL 26/26] migration/colo: Fix bdrv_graph_rdlock_main_loop: Assertion `!qemu_in_coroutine()' failed Peter Xu
2024-04-24 6:50 ` [PULL 00/26] Migration 20240423 patches Richard Henderson
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=20240423223813.3237060-21-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=anthony.perard@citrix.com \
--cc=clg@redhat.com \
--cc=david@redhat.com \
--cc=farosas@suse.de \
--cc=mst@redhat.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--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).