From nobody Tue Nov 26 09:46:57 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 170906689753495.0221907697495; Tue, 27 Feb 2024 12:48:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ku-00061H-SV; Tue, 27 Feb 2024 15:46: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 1rf1ob-0003Sy-5C for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:29 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rf1oY-0001Vm-J2 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:28 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklk16cF7z4wyr; Wed, 28 Feb 2024 05:04:25 +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 4Tkljx11Djz4wyj; Wed, 28 Feb 2024 05:04:20 +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?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Stefano Stabellini , Anthony Perard , Paul Durrant , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand Subject: [PATCH v2 08/21] memory: Add Error** argument to .log_global*() handlers Date: Tue, 27 Feb 2024 19:03:32 +0100 Message-ID: <20240227180345.548960-9-clg@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240227180345.548960-1-clg@redhat.com> References: <20240227180345.548960-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=150.107.74.76; envelope-from=SRS0=GitP=KE=redhat.com=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:32 -0500 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: 1709066898797100008 Modify all log_global*() handlers to take an Error** parameter and return a bool. A new MEMORY_LISTENER_CALL_LOG_GLOBAL macro looping on the listeners is introduced to handle a possible error, which will would interrupt the loop if necessary. To be noted a change in memory_global_dirty_log_start() behavior as it will return as soon as an error is detected. Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paul Durrant Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: David Hildenbrand Signed-off-by: C=C3=A9dric Le Goater --- include/exec/memory.h | 15 ++++++-- hw/i386/xen/xen-hvm.c | 6 ++-- hw/vfio/common.c | 8 +++-- hw/virtio/vhost.c | 6 ++-- system/memory.c | 83 +++++++++++++++++++++++++++++++++++++------ system/physmem.c | 5 +-- 6 files changed, 101 insertions(+), 22 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 8626a355b310ed7b1a1db7978ba4b394032c2f15..4bc146c5ebdd377cd14a4e462f3= 2cc945db5a0a8 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -998,8 +998,11 @@ struct MemoryListener { * active at that time. * * @listener: The #MemoryListener. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. */ - void (*log_global_start)(MemoryListener *listener); + bool (*log_global_start)(MemoryListener *listener, Error **errp); =20 /** * @log_global_stop: @@ -1009,8 +1012,11 @@ struct MemoryListener { * the address space. * * @listener: The #MemoryListener. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. */ - void (*log_global_stop)(MemoryListener *listener); + bool (*log_global_stop)(MemoryListener *listener, Error **errp); =20 /** * @log_global_after_sync: @@ -1019,8 +1025,11 @@ struct MemoryListener { * for any #MemoryRegionSection. * * @listener: The #MemoryListener. + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. */ - void (*log_global_after_sync)(MemoryListener *listener); + bool (*log_global_after_sync)(MemoryListener *listener, Error **errp); =20 /** * @eventfd_add: diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index f42621e6742552035122ea58092c91c3458338ff..925a207b494b4eed52d5f360b55= 4f18ac8a9806d 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -446,16 +446,18 @@ static void xen_log_sync(MemoryListener *listener, Me= moryRegionSection *section) int128_get64(section->size)); } =20 -static void xen_log_global_start(MemoryListener *listener) +static bool xen_log_global_start(MemoryListener *listener, Error **errp) { if (xen_enabled()) { xen_in_migration =3D true; } + return true; } =20 -static void xen_log_global_stop(MemoryListener *listener) +static bool xen_log_global_stop(MemoryListener *listener, Error **errp) { xen_in_migration =3D false; + return true; } =20 static const MemoryListener xen_memory_listener =3D { diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 059bfdc07a85e2eb908df828c1f42104d683e911..8bba95ba6a2010b78cae54c6905= 857686bbb6309 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1075,7 +1075,8 @@ out: return ret; } =20 -static void vfio_listener_log_global_start(MemoryListener *listener) +static bool vfio_listener_log_global_start(MemoryListener *listener, + Error **errp) { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); @@ -1092,9 +1093,11 @@ static void vfio_listener_log_global_start(MemoryLis= tener *listener) ret, strerror(-ret)); vfio_set_migration_error(ret); } + return !!ret; } =20 -static void vfio_listener_log_global_stop(MemoryListener *listener) +static bool vfio_listener_log_global_stop(MemoryListener *listener, + Error **errp) { VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); @@ -1111,6 +1114,7 @@ static void vfio_listener_log_global_stop(MemoryListe= ner *listener) ret, strerror(-ret)); vfio_set_migration_error(ret); } + return !!ret; } =20 static int vfio_device_dma_logging_report(VFIODevice *vbasedev, hwaddr iov= a, diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 2c9ac794680ea9b65eba6cc22e70cf141e90aa73..7a555f941934991a72a2817e550= 5fe0ce6d6fc64 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1044,7 +1044,7 @@ check_dev_state: return r; } =20 -static void vhost_log_global_start(MemoryListener *listener) +static bool vhost_log_global_start(MemoryListener *listener, Error **errp) { int r; =20 @@ -1052,9 +1052,10 @@ static void vhost_log_global_start(MemoryListener *l= istener) if (r < 0) { abort(); } + return true; } =20 -static void vhost_log_global_stop(MemoryListener *listener) +static bool vhost_log_global_stop(MemoryListener *listener, Error **errp) { int r; =20 @@ -1062,6 +1063,7 @@ static void vhost_log_global_stop(MemoryListener *lis= tener) if (r < 0) { abort(); } + return true; } =20 static void vhost_log_start(MemoryListener *listener, diff --git a/system/memory.c b/system/memory.c index a229a79988fce2aa3cb77e3a130db4c694e8cd49..af06157ead5b1272548e87f79ab= 9fb3036055328 100644 --- a/system/memory.c +++ b/system/memory.c @@ -127,6 +127,35 @@ enum ListenerDirection { Forward, Reverse }; } \ } while (0) =20 +#define MEMORY_LISTENER_CALL_LOG_GLOBAL(_callback, _direction, _errp, \ + _args...) \ + do { \ + MemoryListener *_listener; \ + \ + switch (_direction) { \ + case Forward: \ + QTAILQ_FOREACH(_listener, &memory_listeners, link) { \ + if (_listener->_callback) { \ + if (!_listener->_callback(_listener, _errp, ##_args)) = { \ + break; \ + } \ + } \ + } \ + break; \ + case Reverse: \ + QTAILQ_FOREACH_REVERSE(_listener, &memory_listeners, link) { \ + if (_listener->_callback) { \ + if (!_listener->_callback(_listener, _errp, ##_args)) = { \ + break; \ + } \ + } \ + } \ + break; \ + default: \ + abort(); \ + }; \ + } while (0) + #define MEMORY_LISTENER_CALL(_as, _callback, _direction, _section, _args..= .) \ do { \ MemoryListener *_listener; \ @@ -2903,7 +2932,13 @@ void memory_global_dirty_log_sync(bool last_stage) =20 void memory_global_after_dirty_log_sync(void) { - MEMORY_LISTENER_CALL_GLOBAL(log_global_after_sync, Forward); + Error *local_err =3D NULL; + + MEMORY_LISTENER_CALL_LOG_GLOBAL(log_global_after_sync, Forward, + &local_err); + if (local_err) { + error_report_err(local_err); + } } =20 /* @@ -2912,18 +2947,22 @@ void memory_global_after_dirty_log_sync(void) */ static unsigned int postponed_stop_flags; static VMChangeStateEntry *vmstate_change; -static void memory_global_dirty_log_stop_postponed_run(void); +static bool memory_global_dirty_log_stop_postponed_run(Error **errp); =20 void memory_global_dirty_log_start(unsigned int flags) { unsigned int old_flags; + Error *local_err =3D NULL; =20 assert(flags && !(flags & (~GLOBAL_DIRTY_MASK))); =20 if (vmstate_change) { /* If there is postponed stop(), operate on it first */ postponed_stop_flags &=3D ~flags; - memory_global_dirty_log_stop_postponed_run(); + if (!memory_global_dirty_log_stop_postponed_run(&local_err)) { + error_report_err(local_err); + return; + } } =20 flags &=3D ~global_dirty_tracking; @@ -2936,15 +2975,22 @@ void memory_global_dirty_log_start(unsigned int fla= gs) trace_global_dirty_changed(global_dirty_tracking); =20 if (!old_flags) { - MEMORY_LISTENER_CALL_GLOBAL(log_global_start, Forward); + MEMORY_LISTENER_CALL_LOG_GLOBAL(log_global_start, Forward, + &local_err); + if (local_err) { + error_report_err(local_err); + return; + } memory_region_transaction_begin(); memory_region_update_pending =3D true; memory_region_transaction_commit(); } } =20 -static void memory_global_dirty_log_do_stop(unsigned int flags) +static bool memory_global_dirty_log_do_stop(unsigned int flags, Error **er= rp) { + ERRP_GUARD(); + assert(flags && !(flags & (~GLOBAL_DIRTY_MASK))); assert((global_dirty_tracking & flags) =3D=3D flags); global_dirty_tracking &=3D ~flags; @@ -2955,39 +3001,49 @@ static void memory_global_dirty_log_do_stop(unsigne= d int flags) memory_region_transaction_begin(); memory_region_update_pending =3D true; memory_region_transaction_commit(); - MEMORY_LISTENER_CALL_GLOBAL(log_global_stop, Reverse); + MEMORY_LISTENER_CALL_LOG_GLOBAL(log_global_stop, Reverse, errp); } + return !*errp; } =20 /* * Execute the postponed dirty log stop operations if there is, then reset * everything (including the flags and the vmstate change hook). */ -static void memory_global_dirty_log_stop_postponed_run(void) +static bool memory_global_dirty_log_stop_postponed_run(Error **errp) { + bool ret =3D true; + /* This must be called with the vmstate handler registered */ assert(vmstate_change); =20 /* Note: postponed_stop_flags can be cleared in log start routine */ if (postponed_stop_flags) { - memory_global_dirty_log_do_stop(postponed_stop_flags); + ret =3D memory_global_dirty_log_do_stop(postponed_stop_flags, errp= ); postponed_stop_flags =3D 0; } =20 qemu_del_vm_change_state_handler(vmstate_change); vmstate_change =3D NULL; + return ret; } =20 static void memory_vm_change_state_handler(void *opaque, bool running, RunState state) { + Error *local_err =3D NULL; + if (running) { - memory_global_dirty_log_stop_postponed_run(); + if (!memory_global_dirty_log_stop_postponed_run(&local_err)) { + error_report_err(local_err); + } } } =20 void memory_global_dirty_log_stop(unsigned int flags) { + Error *local_err =3D NULL; + if (!runstate_is_running()) { /* Postpone the dirty log stop, e.g., to when VM starts again */ if (vmstate_change) { @@ -3001,7 +3057,9 @@ void memory_global_dirty_log_stop(unsigned int flags) return; } =20 - memory_global_dirty_log_do_stop(flags); + if (!memory_global_dirty_log_do_stop(flags, &local_err)) { + error_report_err(local_err); + } } =20 static void listener_add_address_space(MemoryListener *listener, @@ -3009,13 +3067,16 @@ static void listener_add_address_space(MemoryListen= er *listener, { FlatView *view; FlatRange *fr; + Error *local_err =3D NULL; =20 if (listener->begin) { listener->begin(listener); } if (global_dirty_tracking) { if (listener->log_global_start) { - listener->log_global_start(listener); + if (!listener->log_global_start(listener, &local_err)) { + error_report_err(local_err); + } } } =20 diff --git a/system/physmem.c b/system/physmem.c index e3ebc19eefd8050a1dee16e3d1449f0c144f751f..9adbf9aea847cd80bdac6dca466= fb476844ac048 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -148,7 +148,7 @@ typedef struct subpage_t { =20 static void io_mem_init(void); static void memory_map_init(void); -static void tcg_log_global_after_sync(MemoryListener *listener); +static bool tcg_log_global_after_sync(MemoryListener *listener, Error **er= rp); static void tcg_commit(MemoryListener *listener); =20 /** @@ -2475,7 +2475,7 @@ static void do_nothing(CPUState *cpu, run_on_cpu_data= d) { } =20 -static void tcg_log_global_after_sync(MemoryListener *listener) +static bool tcg_log_global_after_sync(MemoryListener *listener, Error **er= rp) { CPUAddressSpace *cpuas; =20 @@ -2507,6 +2507,7 @@ static void tcg_log_global_after_sync(MemoryListener = *listener) cpuas =3D container_of(listener, CPUAddressSpace, tcg_as_listener); run_on_cpu(cpuas->cpu, do_nothing, RUN_ON_CPU_NULL); } + return true; } =20 static void tcg_commit_cpu(CPUState *cpu, run_on_cpu_data data) --=20 2.43.2