From nobody Tue Nov 26 07:52:36 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 1709066886614565.5876069132537; Tue, 27 Feb 2024 12:48:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ka-0005qN-Fg; Tue, 27 Feb 2024 15:45:41 -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 1rf1oG-0002gn-7A for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:08 -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 1rf1oD-0001Sk-Fp for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:07 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TkljV4ph8z4wxt; Wed, 28 Feb 2024 05:03:58 +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 4TkljS0WQMz4wcN; Wed, 28 Feb 2024 05:03:55 +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?= Subject: [PATCH v2 01/21] migration: Report error when shutdown fails Date: Tue, 27 Feb 2024 19:03:25 +0100 Message-ID: <20240227180345.548960-2-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:26 -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: 1709066888761100005 This will help detect issues regarding I/O channels usage. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Signed-off-by: C=C3=A9dric Le Goater --- migration/qemu-file.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 94231ff2955c80b3d0fab11a40510d34c334a826..b69e0c62e2fcf21d346a3687df7= eebee23791fdc 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -62,6 +62,8 @@ struct QEMUFile { */ int qemu_file_shutdown(QEMUFile *f) { + Error *err =3D NULL; + /* * We must set qemufile error before the real shutdown(), otherwise * there can be a race window where we thought IO all went though @@ -90,7 +92,8 @@ int qemu_file_shutdown(QEMUFile *f) return -ENOSYS; } =20 - if (qio_channel_shutdown(f->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, NULL) < 0)= { + if (qio_channel_shutdown(f->ioc, QIO_CHANNEL_SHUTDOWN_BOTH, &err) < 0)= { + error_report_err(err); return -EIO; } =20 --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 170906677867865.58253548445282; Tue, 27 Feb 2024 12:46:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KZ-0005pW-Af; Tue, 27 Feb 2024 15:45:39 -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 1rf1oQ-0003FH-1a for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:18 -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 1rf1oD-0001Sx-Q6 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:16 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TkljY5zBnz4wxv; Wed, 28 Feb 2024 05:04:01 +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 4TkljW1mL0z4wcN; Wed, 28 Feb 2024 05:03:58 +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?= Subject: [PATCH v2 02/21] migration: Remove SaveStateHandler and LoadStateHandler typedefs Date: Tue, 27 Feb 2024 19:03:26 +0100 Message-ID: <20240227180345.548960-3-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:27 -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: 1709066780428100008 They are only used once. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Fabiano Rosas Reviewed-by: Peter Xu --- include/migration/register.h | 4 ++-- include/qemu/typedefs.h | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index 9ab1f79512c605f0c88a45b560c57486fa054441..2e6a7d766e62f64940086b7b511= 249c9ff21fa62 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -18,7 +18,7 @@ =20 typedef struct SaveVMHandlers { /* This runs inside the BQL. */ - SaveStateHandler *save_state; + void (*save_state)(QEMUFile *f, void *opaque); =20 /* * save_prepare is called early, even before migration starts, and can= be @@ -71,7 +71,7 @@ typedef struct SaveVMHandlers { /* This calculate the exact remaining data to transfer */ void (*state_pending_exact)(void *opaque, uint64_t *must_precopy, uint64_t *can_postcopy); - LoadStateHandler *load_state; + int (*load_state)(QEMUFile *f, void *opaque, int version_id); int (*load_setup)(QEMUFile *f, void *opaque); int (*load_cleanup)(void *opaque); /* Called when postcopy migration wants to resume from failure */ diff --git a/include/qemu/typedefs.h b/include/qemu/typedefs.h index d7c703b4ae9c91d9638111bcaafc656686e1dbb8..5fcba1c1b467826d4f7b6bd2876= 90d33cdc48acf 100644 --- a/include/qemu/typedefs.h +++ b/include/qemu/typedefs.h @@ -150,8 +150,6 @@ typedef struct IRQState *qemu_irq; /* * Function types */ -typedef void SaveStateHandler(QEMUFile *f, void *opaque); -typedef int LoadStateHandler(QEMUFile *f, void *opaque, int version_id); typedef void (*qemu_irq_handler)(void *opaque, int n, int level); =20 #endif /* QEMU_TYPEDEFS_H */ --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066898476582.7196533011659; Tue, 27 Feb 2024 12:48:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ka-0005qK-Dw; Tue, 27 Feb 2024 15:45:41 -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 1rf1oO-0003F4-Hd for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:17 -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 1rf1oJ-0001TC-EW for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:16 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tkljd05qnz4wyh; Wed, 28 Feb 2024 05:04:05 +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 4TkljZ2xMPz4wcN; Wed, 28 Feb 2024 05:04:02 +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?= Subject: [PATCH v2 03/21] migration: Add documentation for SaveVMHandlers Date: Tue, 27 Feb 2024 19:03:27 +0100 Message-ID: <20240227180345.548960-4-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:26 -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: 1709066898780100007 The SaveVMHandlers structure is still in use for complex subsystems and devices. Document the handlers since we are going to modify a few later. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Peter Xu --- include/migration/register.h | 257 +++++++++++++++++++++++++++++++---- 1 file changed, 231 insertions(+), 26 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index 2e6a7d766e62f64940086b7b511249c9ff21fa62..2cc71ec45f65bf2884c9e7a823d= 2968752f15c20 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -16,30 +16,129 @@ =20 #include "hw/vmstate-if.h" =20 +/** + * struct SaveVMHandlers: handler structure to finely control + * migration of complex subsystems and devices, such as RAM, block and + * VFIO. + */ typedef struct SaveVMHandlers { - /* This runs inside the BQL. */ + + /* The following handlers runs inside the BQL. */ + + /** + * @save_state + * + * Saves state section on the source using the latest state format + * version. + * + * Legacy method. Should be deprecated when all users are ported + * to VMState. + * + * @f: QEMUFile where to send the data + * @opaque: data pointer passed to register_savevm_live() + */ void (*save_state)(QEMUFile *f, void *opaque); =20 - /* - * save_prepare is called early, even before migration starts, and can= be - * used to perform early checks. + /** + * @save_prepare + * + * Called early, even before migration starts, and can be used to + * perform early checks. + * + * @opaque: data pointer passed to register_savevm_live() + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error */ int (*save_prepare)(void *opaque, Error **errp); + + /** + * @save_setup + * + * Initializes the data structures on the source and transmits + * first section containing information on the device + * + * @f: QEMUFile where to send the data + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*save_setup)(QEMUFile *f, void *opaque); + + /** + * @save_cleanup + * + * Performs save related cleanup + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ void (*save_cleanup)(void *opaque); + + /** + * @save_live_complete_postcopy + * + * Called at the end of postcopy for all postcopyiable devices. + * + * @f: QEMUFile where to send the data + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*save_live_complete_postcopy)(QEMUFile *f, void *opaque); + + /** + * @save_live_complete_precopy + * + * Transmits the last section for the device containing any + * remaining data. + * + * @f: QEMUFile where to send the data + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*save_live_complete_precopy)(QEMUFile *f, void *opaque); =20 /* This runs both outside and inside the BQL. */ + + /** + * @is_active + * + * Will skip a state section if not active + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns true if state section is active else false + */ bool (*is_active)(void *opaque); + + /** + * @has_postcopy + * + * checks if a device supports postcopy + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns true for postcopy support else false + */ bool (*has_postcopy)(void *opaque); =20 - /* is_active_iterate - * If it is not NULL then qemu_savevm_state_iterate will skip iteratio= n if - * it returns false. For example, it is needed for only-postcopy-state= s, - * which needs to be handled by qemu_savevm_state_setup and - * qemu_savevm_state_pending, but do not need iterations until not in - * postcopy stage. + /** + * @is_active_iterate + * + * As #SaveVMHandlers.is_active(), will skip an inactive state + * section in qemu_savevm_state_iterate. + * + * For example, it is needed for only-postcopy-states, which needs + * to be handled by qemu_savevm_state_setup() and + * qemu_savevm_state_pending(), but do not need iterations until + * not in postcopy stage. + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns true if state section is active else false */ bool (*is_active_iterate)(void *opaque); =20 @@ -48,44 +147,150 @@ typedef struct SaveVMHandlers { * use data that is local to the migration thread or protected * by other locks. */ + + /** + * @save_live_iterate + * + * Should send a chunk of data until the point that stream + * bandwidth limits tell it to stop. Each call generates one + * section. + * + * @f: QEMUFile where to send the data + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*save_live_iterate)(QEMUFile *f, void *opaque); =20 /* This runs outside the BQL! */ - /* Note for save_live_pending: - * must_precopy: - * - must be migrated in precopy or in stopped state - * - i.e. must be migrated before target start - * - * can_postcopy: - * - can migrate in postcopy or in stopped state - * - i.e. can migrate after target start - * - some can also be migrated during precopy (RAM) - * - some must be migrated after source stops (block-dirty-bitmap) - * - * Sum of can_postcopy and must_postcopy is the whole amount of + + /** + * @state_pending_estimate + * + * This estimates the remaining data to transfer + * + * Sum of @can_postcopy and @must_postcopy is the whole amount of * pending data. + * + * @opaque: data pointer passed to register_savevm_live() + * @must_precopy: amount of data that must be migrated in precopy + * or in stopped state, i.e. that must be migrated + * before target start. + * @can_postcopy: amount of data that can be migrated in postcopy + * or in stopped state, i.e. after target start. + * Some can also be migrated during precopy (RAM). + * Some must be migrated after source stops + * (block-dirty-bitmap) */ - /* This estimates the remaining data to transfer */ void (*state_pending_estimate)(void *opaque, uint64_t *must_precopy, uint64_t *can_postcopy); - /* This calculate the exact remaining data to transfer */ + + /** + * @state_pending_exact + * + * This calculate the exact remaining data to transfer + * + * Sum of @can_postcopy and @must_postcopy is the whole amount of + * pending data. + * + * @opaque: data pointer passed to register_savevm_live() + * @must_precopy: amount of data that must be migrated in precopy + * or in stopped state, i.e. that must be migrated + * before target start. + * @can_postcopy: amount of data that can be migrated in postcopy + * or in stopped state, i.e. after target start. + * Some can also be migrated during precopy (RAM). + * Some must be migrated after source stops + * (block-dirty-bitmap) + */ void (*state_pending_exact)(void *opaque, uint64_t *must_precopy, uint64_t *can_postcopy); + + /** + * @load_state + * + * Load sections generated by any of the save functions that + * generate sections. + * + * Legacy method. Should be deprecated when all users are ported + * to VMState. + * + * @f: QEMUFile where to receive the data + * @opaque: data pointer passed to register_savevm_live() + * @version_id: the maximum version_id supported + * + * Returns zero to indicate success and negative for error + */ int (*load_state)(QEMUFile *f, void *opaque, int version_id); + + /** + * @load_setup + * + * Initializes the data structures on the destination. + * + * @f: QEMUFile where to receive the data + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*load_setup)(QEMUFile *f, void *opaque); + + /** + * @load_cleanup + * + * Performs cleanup of load data structures + * + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*load_cleanup)(void *opaque); - /* Called when postcopy migration wants to resume from failure */ + + /** + * @resume_prepare + * + * Called when postcopy migration wants to resume from failure + * + * @s: Current migration state + * @opaque: data pointer passed to register_savevm_live() + * + * Returns zero to indicate success and negative for error + */ int (*resume_prepare)(MigrationState *s, void *opaque); - /* Checks if switchover ack should be used. Called only in dest */ + + /** + * @switchover_ack_needed + * + * Checks if switchover ack should be used. Called only on + * destination. + * + * @opaque: data pointer passed to register_savevm_live() + */ bool (*switchover_ack_needed)(void *opaque); } SaveVMHandlers; =20 +/** + * register_savevm_live: Register a set of custom migration handlers + * + * @idstr: state section identifier + * @instance_id: instance id + * @version_id: version id supported + * @ops: SaveVMHandlers structurex + * @opaque: data pointer passed SaveVMHandlers handlers + */ int register_savevm_live(const char *idstr, uint32_t instance_id, int version_id, const SaveVMHandlers *ops, void *opaque); =20 +/** + * unregister_savevm: Unregister custom migration handlers + * + * @obj: object associated with state section + * @idstr: state section identifier + * @opaque: data pointer passed to register_savevm_live() + */ void unregister_savevm(VMStateIf *obj, const char *idstr, void *opaque); =20 #endif --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066779682630.0377881151607; Tue, 27 Feb 2024 12:46:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KV-0005Vp-6e; Tue, 27 Feb 2024 15:45:35 -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 1rf1oL-00036d-Ov for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:13 -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 1rf1oJ-0001Uq-An for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:13 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tkljh1Rbjz4wcN; Wed, 28 Feb 2024 05:04:08 +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 4Tkljd49hDz4wyj; Wed, 28 Feb 2024 05:04:05 +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?= Subject: [PATCH v2 04/21] migration: Do not call PRECOPY_NOTIFY_SETUP notifiers in case of error Date: Tue, 27 Feb 2024 19:03:28 +0100 Message-ID: <20240227180345.548960-5-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:26 -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: 1709066780406100007 When commit bd2270608fa0 ("migration/ram.c: add a notifier chain for precopy") added PRECOPY_NOTIFY_SETUP notifiers at the end of qemu_savevm_state_setup(), it didn't take into account a possible error in the loop calling vmstate_save() or .save_setup() handlers. Check ret value before calling the notifiers. Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Peter Xu --- migration/savevm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/migration/savevm.c b/migration/savevm.c index d612c8a9020b204d5d078d5df85f0e6449c27645..51876f2ef674bb76c7e7ef96e11= 19a083883deac 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1316,7 +1316,7 @@ void qemu_savevm_state_setup(QEMUFile *f) MigrationState *ms =3D migrate_get_current(); SaveStateEntry *se; Error *local_err =3D NULL; - int ret; + int ret =3D 0; =20 json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size()); json_writer_start_array(ms->vmdesc, "devices"); @@ -1350,6 +1350,10 @@ void qemu_savevm_state_setup(QEMUFile *f) } } =20 + if (ret) { + return; + } + if (precopy_notify(PRECOPY_NOTIFY_SETUP, &local_err)) { error_report_err(local_err); } --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066883918508.6210989438115; Tue, 27 Feb 2024 12:48:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ku-00060M-35; 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-0003SK-1w 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 1rf1oL-0001V6-DC 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 4Tkljl2ffDz4wyk; Wed, 28 Feb 2024 05:04:11 +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 4Tkljh5WjMz4wyj; Wed, 28 Feb 2024 05:04:08 +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?= Subject: [PATCH v2 05/21] migration: Add Error** argument to qemu_savevm_state_setup() Date: Tue, 27 Feb 2024 19:03:29 +0100 Message-ID: <20240227180345.548960-6-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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:31 -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: 1709066884781100003 This prepares ground for the changes coming next which add an Error** argument to the .save_setup() handler. Callers of qemu_savevm_state_setup() now handle the error and fail earlier. This is a functional change that should be examined closely. Signed-off-by: C=C3=A9dric Le Goater --- migration/savevm.h | 2 +- migration/migration.c | 20 ++++++++++++++++++-- migration/savevm.c | 14 +++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/migration/savevm.h b/migration/savevm.h index 74669733dd63a080b765866c703234a5c4939223..9ec96a995c93a42aad621595f0e= d58596c532328 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -32,7 +32,7 @@ bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_non_migratable_list(strList **reasons); int qemu_savevm_state_prepare(Error **errp); -void qemu_savevm_state_setup(QEMUFile *f); +int qemu_savevm_state_setup(QEMUFile *f, Error **errp); bool qemu_savevm_state_guest_unplug_pending(void); int qemu_savevm_state_resume_prepare(MigrationState *s); void qemu_savevm_state_header(QEMUFile *f); diff --git a/migration/migration.c b/migration/migration.c index 5316bbe6704742e604ae55dc7b47a4e11e73c2a4..c1a62b696f62c0d5aca0505e58b= c4dc0ff561fde 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3314,6 +3314,8 @@ static void *migration_thread(void *opaque) int64_t setup_start =3D qemu_clock_get_ms(QEMU_CLOCK_HOST); MigThrError thr_error; bool urgent =3D false; + Error *local_err =3D NULL; + int ret; =20 thread =3D migration_threads_add("live_migration", qemu_get_thread_id(= )); =20 @@ -3357,9 +3359,15 @@ static void *migration_thread(void *opaque) } =20 bql_lock(); - qemu_savevm_state_setup(s->to_dst_file); + ret =3D qemu_savevm_state_setup(s->to_dst_file, &local_err); bql_unlock(); =20 + if (ret) { + migrate_set_error(s, local_err); + error_free(local_err); + goto out; + } + qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); =20 @@ -3436,6 +3444,8 @@ static void *bg_migration_thread(void *opaque) MigThrError thr_error; QEMUFile *fb; bool early_fail =3D true; + Error *local_err =3D NULL; + int ret; =20 rcu_register_thread(); object_ref(OBJECT(s)); @@ -3469,9 +3479,15 @@ static void *bg_migration_thread(void *opaque) =20 bql_lock(); qemu_savevm_state_header(s->to_dst_file); - qemu_savevm_state_setup(s->to_dst_file); + ret =3D qemu_savevm_state_setup(s->to_dst_file, &local_err); bql_unlock(); =20 + if (ret) { + migrate_set_error(s, local_err); + error_free(local_err); + goto fail; + } + qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP, MIGRATION_STATUS_ACTIVE); =20 diff --git a/migration/savevm.c b/migration/savevm.c index 51876f2ef674bb76c7e7ef96e1119a083883deac..bc168371a31acf85f29f2c284be= 181250db45df4 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1311,11 +1311,10 @@ int qemu_savevm_state_prepare(Error **errp) return 0; } =20 -void qemu_savevm_state_setup(QEMUFile *f) +int qemu_savevm_state_setup(QEMUFile *f, Error **errp) { MigrationState *ms =3D migrate_get_current(); SaveStateEntry *se; - Error *local_err =3D NULL; int ret =3D 0; =20 json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size()); @@ -1351,12 +1350,10 @@ void qemu_savevm_state_setup(QEMUFile *f) } =20 if (ret) { - return; + return ret; } =20 - if (precopy_notify(PRECOPY_NOTIFY_SETUP, &local_err)) { - error_report_err(local_err); - } + return precopy_notify(PRECOPY_NOTIFY_SETUP, errp); } =20 int qemu_savevm_state_resume_prepare(MigrationState *s) @@ -1725,7 +1722,10 @@ static int qemu_savevm_state(QEMUFile *f, Error **er= rp) ms->to_dst_file =3D f; =20 qemu_savevm_state_header(f); - qemu_savevm_state_setup(f); + ret =3D qemu_savevm_state_setup(f, errp); + if (ret) { + return ret; + } =20 while (qemu_file_get_error(f) =3D=3D 0) { if (qemu_savevm_state_iterate(f, false) > 0) { --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066903076779.0709946297109; Tue, 27 Feb 2024 12:48:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ku-00060N-1e; 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 1rf1oX-0003P4-PS for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:28 -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 1rf1oR-0001Vm-D8 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:24 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tkljs2qJFz4wyf; Wed, 28 Feb 2024 05:04:17 +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 4Tkljl6mn1z4wyj; Wed, 28 Feb 2024 05:04:11 +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?= , Nicholas Piggin , Harsh Prateek Bora , Halil Pasic , Thomas Huth , Eric Blake , Vladimir Sementsov-Ogievskiy , John Snow , Stefan Hajnoczi Subject: [PATCH v2 06/21] migration: Add Error** argument to .save_setup() handler Date: Tue, 27 Feb 2024 19:03:30 +0100 Message-ID: <20240227180345.548960-7-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: 1709066904838100004 The purpose is to record a potential error in the migration stream if qemu_savevm_state_setup() fails. Most of the current .save_setup() handlers can be modified to use the Error argument instead of managing their own and calling locally error_report(). The following patches will introduce such changes for VFIO first. Cc: Nicholas Piggin Cc: Harsh Prateek Bora Cc: Halil Pasic Cc: Thomas Huth Cc: Eric Blake Cc: Vladimir Sementsov-Ogievskiy Cc: John Snow Cc: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Xu Signed-off-by: C=C3=A9dric Le Goater --- Changes in v2:=20 - dropped qemu_file_set_error_obj(f, ret, local_err);=20 include/migration/register.h | 3 ++- hw/ppc/spapr.c | 2 +- hw/s390x/s390-stattrib.c | 2 +- hw/vfio/migration.c | 2 +- migration/block-dirty-bitmap.c | 2 +- migration/block.c | 2 +- migration/ram.c | 3 ++- migration/savevm.c | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index 2cc71ec45f65bf2884c9e7a823d2968752f15c20..96eae9dba2970552c379c732393= e3ab6ef578a58 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -60,10 +60,11 @@ typedef struct SaveVMHandlers { * * @f: QEMUFile where to send the data * @opaque: data pointer passed to register_savevm_live() + * @errp: pointer to Error*, to store an error if it happens. * * Returns zero to indicate success and negative for error */ - int (*save_setup)(QEMUFile *f, void *opaque); + int (*save_setup)(QEMUFile *f, void *opaque, Error **errp); =20 /** * @save_cleanup diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 55263f0815ed7671b32ea20b394ae71c82e616cb..045c024ffa76eacfc496bd486cb= 6cafbee2df73e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2142,7 +2142,7 @@ static const VMStateDescription vmstate_spapr =3D { } }; =20 -static int htab_save_setup(QEMUFile *f, void *opaque) +static int htab_save_setup(QEMUFile *f, void *opaque, Error **errp) { SpaprMachineState *spapr =3D opaque; =20 diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index c483b62a9b5f71772639fc180bdad15ecb6711cb..c934df424a555d83d2198f5ddfc= 0cbe0ea98e9ec 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -166,7 +166,7 @@ static int cmma_load(QEMUFile *f, void *opaque, int ver= sion_id) return ret; } =20 -static int cmma_save_setup(QEMUFile *f, void *opaque) +static int cmma_save_setup(QEMUFile *f, void *opaque, Error **errp) { S390StAttribState *sas =3D S390_STATTRIB(opaque); S390StAttribClass *sac =3D S390_STATTRIB_GET_CLASS(sas); diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 70e6b1a709f9b67e4c9eb41033d76347275cac42..8bcb4bc73cd5ba5338e3ffa4d90= 7d0e6bfbb9485 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -378,7 +378,7 @@ static int vfio_save_prepare(void *opaque, Error **errp) return 0; } =20 -static int vfio_save_setup(QEMUFile *f, void *opaque) +static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 2708abf3d762de774ed294d3fdb8e56690d2974c..16f84e6c57c2403a8c2d6319f4e= 7b6360dade28c 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -1213,7 +1213,7 @@ fail: return ret; } =20 -static int dirty_bitmap_save_setup(QEMUFile *f, void *opaque) +static int dirty_bitmap_save_setup(QEMUFile *f, void *opaque, Error **errp) { DBMSaveState *s =3D &((DBMState *)opaque)->save; SaveBitmapState *dbms =3D NULL; diff --git a/migration/block.c b/migration/block.c index 8c6ebafacc1ffe930d1d4f19d968817b14852c69..df15319ceab66201b043f15eac1= b0a7d6522b60c 100644 --- a/migration/block.c +++ b/migration/block.c @@ -708,7 +708,7 @@ static void block_migration_cleanup(void *opaque) blk_mig_unlock(); } =20 -static int block_save_setup(QEMUFile *f, void *opaque) +static int block_save_setup(QEMUFile *f, void *opaque, Error **errp) { int ret; =20 diff --git a/migration/ram.c b/migration/ram.c index 4649a8120492a03d331d660622e1a0a51adb0a96..745482899e18c86b73261b683c1= bec04039a76d2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2930,8 +2930,9 @@ void qemu_guest_free_page_hint(void *addr, size_t len) * * @f: QEMUFile where to send the data * @opaque: RAMState pointer + * @errp: pointer to Error*, to store an error if it happens. */ -static int ram_save_setup(QEMUFile *f, void *opaque) +static int ram_save_setup(QEMUFile *f, void *opaque, Error **errp) { RAMState **rsp =3D opaque; RAMBlock *block; diff --git a/migration/savevm.c b/migration/savevm.c index bc168371a31acf85f29f2c284be181250db45df4..b5b3b51bad94dc4c04ae22cd687= ba111299339aa 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1341,7 +1341,7 @@ int qemu_savevm_state_setup(QEMUFile *f, Error **errp) } save_section_header(f, se, QEMU_VM_SECTION_START); =20 - ret =3D se->ops->save_setup(f, se->opaque); + ret =3D se->ops->save_setup(f, se->opaque, errp); save_section_footer(f, se); if (ret < 0) { qemu_file_set_error(f, ret); --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066843271162.28252126499558; Tue, 27 Feb 2024 12:47:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kh-0005tz-6D; Tue, 27 Feb 2024 15:45:53 -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 1rf1oX-0003P6-RR for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:28 -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 1rf1oV-0001WB-4S for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:25 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tkljw40k5z4wyq; Wed, 28 Feb 2024 05:04:20 +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 4Tkljs6vMDz4wyj; Wed, 28 Feb 2024 05:04:17 +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?= Subject: [PATCH v2 07/21] migration: Add Error** argument to .load_setup() handler Date: Tue, 27 Feb 2024 19:03:31 +0100 Message-ID: <20240227180345.548960-8-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:28 -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: 1709066844609100003 This will be useful to report errors at a higher level, mostly in VFIO today. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Peter Xu --- include/migration/register.h | 3 ++- hw/vfio/migration.c | 2 +- migration/ram.c | 3 ++- migration/savevm.c | 10 ++++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index 96eae9dba2970552c379c732393e3ab6ef578a58..2cfc167f717de8e08c1ca8accdc= 3011c03eb1554 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -231,10 +231,11 @@ typedef struct SaveVMHandlers { * * @f: QEMUFile where to receive the data * @opaque: data pointer passed to register_savevm_live() + * @errp: pointer to Error*, to store an error if it happens. * * Returns zero to indicate success and negative for error */ - int (*load_setup)(QEMUFile *f, void *opaque); + int (*load_setup)(QEMUFile *f, void *opaque, Error **errp); =20 /** * @load_cleanup diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 8bcb4bc73cd5ba5338e3ffa4d907d0e6bfbb9485..2dfbe671f6f45aa530c7341177b= b532d8292cecd 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -580,7 +580,7 @@ static void vfio_save_state(QEMUFile *f, void *opaque) } } =20 -static int vfio_load_setup(QEMUFile *f, void *opaque) +static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp) { VFIODevice *vbasedev =3D opaque; =20 diff --git a/migration/ram.c b/migration/ram.c index 745482899e18c86b73261b683c1bec04039a76d2..d648134133fc22cd91c7b206419= 8a90287ee733d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3498,8 +3498,9 @@ void colo_release_ram_cache(void) * * @f: QEMUFile where to receive the data * @opaque: RAMState pointer + * @errp: pointer to Error*, to store an error if it happens. */ -static int ram_load_setup(QEMUFile *f, void *opaque) +static int ram_load_setup(QEMUFile *f, void *opaque, Error **errp) { xbzrle_load_setup(); ramblock_recv_map_init(); diff --git a/migration/savevm.c b/migration/savevm.c index b5b3b51bad94dc4c04ae22cd687ba111299339aa..a4ef41d3ff5b471a1cd4166c2dc= 5813e44ea3a5a 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2741,7 +2741,7 @@ static void qemu_loadvm_state_switchover_ack_needed(M= igrationIncomingState *mis) trace_loadvm_state_switchover_ack_needed(mis->switchover_ack_pending_n= um); } =20 -static int qemu_loadvm_state_setup(QEMUFile *f) +static int qemu_loadvm_state_setup(QEMUFile *f, Error **errp) { SaveStateEntry *se; int ret; @@ -2757,10 +2757,11 @@ static int qemu_loadvm_state_setup(QEMUFile *f) } } =20 - ret =3D se->ops->load_setup(f, se->opaque); + ret =3D se->ops->load_setup(f, se->opaque, errp); if (ret < 0) { + error_prepend(errp, "Load state of device %s failed: ", + se->idstr); qemu_file_set_error(f, ret); - error_report("Load state of device %s failed", se->idstr); return ret; } } @@ -2941,7 +2942,8 @@ int qemu_loadvm_state(QEMUFile *f) return ret; } =20 - if (qemu_loadvm_state_setup(f) !=3D 0) { + if (qemu_loadvm_state_setup(f, &local_err) !=3D 0) { + error_report_err(local_err); return -EINVAL; } =20 --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 From nobody Tue Nov 26 07:52:36 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 1709066849749424.4197785505105; Tue, 27 Feb 2024 12:47:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ky-00064x-50; Tue, 27 Feb 2024 15:46: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 1rf1oi-0003uo-3I for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:36 -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 1rf1of-0001X1-IJ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:35 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklk746g7z4wyt; Wed, 28 Feb 2024 05:04:31 +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 4Tklk23Xq1z4wyj; Wed, 28 Feb 2024 05:04:26 +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 , Hyman Huang Subject: [PATCH v2 09/21] memory: Add Error** argument to the global_dirty_log routines Date: Tue, 27 Feb 2024 19:03:33 +0100 Message-ID: <20240227180345.548960-10-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-Mailman-Approved-At: Tue, 27 Feb 2024 15:45:29 -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: 1709066850702100001 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 Signed-off-by: C=C3=A9dric Le Goater --- 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..8b019465ab13ce85c03075c8086= 5a0865ea1feed 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -2576,15 +2576,21 @@ void memory_listener_unregister(MemoryListener *lis= tener); * 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 * * @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); =20 void mtree_info(bool flatview, bool dispatch_tree, bool owner, bool disabl= ed); =20 diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 925a207b494b4eed52d5f360b554f18ac8a9806d..286269b47572d90e57df5ff4483= 5bb5f8e16c7ad 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); } } =20 diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 1d2e85746fb7b10eb7f149976970f9a92125af8a..34f6d803ff5f4e6ccf2e06aaaed= 65a336c4be469 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -90,11 +90,17 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord d= irty_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); } else { - memory_global_dirty_log_stop(flag); + ret =3D 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 =3D 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 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 d648134133fc22cd91c7b2064198a90287ee733d..9fb1875aad73b2fa009199bdfa8= 960339df7287d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2391,6 +2391,7 @@ static void ram_save_cleanup(void *opaque) { RAMState **rsp =3D opaque; RAMBlock *block; + Error *local_err =3D NULL; =20 /* We don't use dirty log with background snapshots */ if (!migrate_background_snapshot()) { @@ -2403,7 +2404,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); + } } } =20 @@ -2800,18 +2804,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. @@ -3451,6 +3468,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(); @@ -3462,7 +3481,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(); @@ -3473,8 +3495,12 @@ void colo_incoming_start_dirty_log(void) void colo_release_ram_cache(void) { RAMBlock *block; + Error *local_err =3D NULL; + + if (!memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION, &local_err))= { + error_report_err(local_err); + } =20 - memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); RAMBLOCK_FOREACH_NOT_IGNORED(block) { g_free(block->bmap); block->bmap =3D NULL; diff --git a/system/memory.c b/system/memory.c index af06157ead5b1272548e87f79ab9fb3036055328..48aed0f8ece1c731849636c442b= 8ab8e5d7ff6a5 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); =20 -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 =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; - 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; } } =20 flags &=3D ~global_dirty_tracking; if (!flags) { - return; + return true; } =20 old_flags =3D global_dirty_tracking; @@ -2975,16 +2974,15 @@ void memory_global_dirty_log_start(unsigned int fla= gs) trace_global_dirty_changed(global_dirty_tracking); =20 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 =3D true; memory_region_transaction_commit(); } + return true; } =20 static bool memory_global_dirty_log_do_stop(unsigned int flags, Error **er= rp) @@ -3040,10 +3038,8 @@ static void memory_vm_change_state_handler(void *opa= que, bool running, } } =20 -void memory_global_dirty_log_stop(unsigned int flags) +bool memory_global_dirty_log_stop(unsigned int flags, Error **errp) { - Error *local_err =3D 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 flag= s) vmstate_change =3D qemu_add_vm_change_state_handler( memory_vm_change_state_handler, NULL); } - return; + return true; } =20 - if (!memory_global_dirty_log_do_stop(flags, &local_err)) { - error_report_err(local_err); - } + return memory_global_dirty_log_do_stop(flags, errp); } =20 static void listener_add_address_space(MemoryListener *listener, --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 170906689526190.88688919848391; Tue, 27 Feb 2024 12:48:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KW-0005Zx-4D; Tue, 27 Feb 2024 15:45:36 -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 1rf1ol-00049O-Nd for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:39 -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 1rf1oi-0001XD-Op for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:39 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkB5Jcbz4wyx; Wed, 28 Feb 2024 05:04:34 +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 4Tklk812QSz4wyj; Wed, 28 Feb 2024 05:04:31 +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?= Subject: [PATCH v2 10/21] migration: Modify ram_init_bitmaps() to report dirty tracking errors Date: Tue, 27 Feb 2024 19:03:34 +0100 Message-ID: <20240227180345.548960-11-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: 1709066896790100003 The .save_setup() handler has now an Error** argument that we can use to propagate errors reported by the .log_global_start() handler. Do that for the RAM. The caller qemu_savevm_state_setup() will store the error under the migration stream for later detection in the migration sequence. Signed-off-by: C=C3=A9dric Le Goater --- migration/ram.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 9fb1875aad73b2fa009199bdfa8960339df7287d..23f4df4779309bbbe164c56c143= 6b60d65749860 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2802,9 +2802,8 @@ static void migration_bitmap_clear_discarded_pages(RA= MState *rs) } } =20 -static void ram_init_bitmaps(RAMState *rs) +static bool ram_init_bitmaps(RAMState *rs, Error **errp) { - Error *local_err =3D NULL; bool ret =3D true; =20 qemu_mutex_lock_ramlist(); @@ -2813,10 +2812,8 @@ static void ram_init_bitmaps(RAMState *rs) ram_list_init_bitmaps(); /* We don't use dirty log with background snapshots */ if (!migrate_background_snapshot()) { - ret =3D memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, - &local_err); + ret =3D memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION, = errp); if (!ret) { - error_report_err(local_err); goto out_unlock; } migration_bitmap_sync_precopy(rs, false); @@ -2826,7 +2823,7 @@ out_unlock: qemu_mutex_unlock_ramlist(); =20 if (!ret) { - return; + return false; } =20 /* @@ -2834,9 +2831,10 @@ out_unlock: * containing all 1s to exclude any discarded pages from migration. */ migration_bitmap_clear_discarded_pages(rs); + return true; } =20 -static int ram_init_all(RAMState **rsp) +static int ram_init_all(RAMState **rsp, Error **errp) { if (ram_state_init(rsp)) { return -1; @@ -2847,7 +2845,9 @@ static int ram_init_all(RAMState **rsp) return -1; } =20 - ram_init_bitmaps(*rsp); + if (!ram_init_bitmaps(*rsp, errp)) { + return -1; + } =20 return 0; } @@ -2961,7 +2961,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque, = Error **errp) =20 /* migration has already setup the bitmap, reuse it. */ if (!migration_in_colo_state()) { - if (ram_init_all(rsp) !=3D 0) { + if (ram_init_all(rsp, errp) !=3D 0) { compress_threads_save_cleanup(); return -1; } --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066903902937.7537775250124; Tue, 27 Feb 2024 12:48:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kd-0005qw-FY; Tue, 27 Feb 2024 15:45:43 -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 1rf1oq-0004OC-Pv for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:44 -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 1rf1ol-0001XR-Uu for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:44 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkF6TBwz4x0m; Wed, 28 Feb 2024 05:04:37 +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 4TklkC2Gl7z4wyy; Wed, 28 Feb 2024 05:04:35 +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?= Subject: [PATCH v2 11/21] migration: Fix migration termination Date: Tue, 27 Feb 2024 19:03:35 +0100 Message-ID: <20240227180345.548960-12-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: 1709066904812100003 Handle migration termination when in SETUP state. This can happen if qemu_savevm_state_setup() fails. Signed-off-by: C=C3=A9dric Le Goater --- migration/migration.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index c1a62b696f62c0d5aca0505e58bc4dc0ff561fde..63294417ff9cae868ad8a167094= a795fc30e4da0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3161,6 +3161,8 @@ static void migration_iteration_finish(MigrationState= *s) } } break; + case MIGRATION_STATUS_SETUP: + break; =20 default: /* Should not reach here, but if so, forgive the VM. */ @@ -3192,6 +3194,8 @@ static void bg_migration_iteration_finish(MigrationSt= ate *s) case MIGRATION_STATUS_CANCELLED: case MIGRATION_STATUS_CANCELLING: break; + case MIGRATION_STATUS_SETUP: + break; =20 default: /* Should not reach here, but if so, forgive the VM. */ --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066924355592.6278016957143; Tue, 27 Feb 2024 12:48:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KV-0005Vu-81; Tue, 27 Feb 2024 15:45:35 -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 1rf1ou-0004bE-6q for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:48 -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 1rf1op-0001YM-2E for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:47 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkK0bC8z4x0n; Wed, 28 Feb 2024 05:04:41 +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 4TklkG3SNTz4wyy; Wed, 28 Feb 2024 05:04:38 +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?= Subject: [PATCH v2 12/21] vfio: Add Error** argument to .set_dirty_page_tracking() handler Date: Tue, 27 Feb 2024 19:03:36 +0100 Message-ID: <20240227180345.548960-13-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: 1709066924897100002 We will use the Error object to improve error reporting in the .log_global*() handlers of VFIO. Add documentation while at it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-container-base.h | 18 ++++++++++++++++-- hw/vfio/common.c | 4 ++-- hw/vfio/container-base.c | 4 ++-- hw/vfio/container.c | 6 +++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index b2813b0c117985425c842d91f011bb895955d738..dec2023eceb6c7d62b0ee35008c= c58f8e695e190 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -81,7 +81,7 @@ int vfio_container_add_section_window(VFIOContainerBase *= bcontainer, void vfio_container_del_section_window(VFIOContainerBase *bcontainer, MemoryRegionSection *section); int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, - bool start); + bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); @@ -120,9 +120,23 @@ struct VFIOIOMMUClass { int (*attach_device)(const char *name, VFIODevice *vbasedev, AddressSpace *as, Error **errp); void (*detach_device)(VFIODevice *vbasedev); + /* migration feature */ + + /** + * @set_dirty_page_tracking + * + * Start or stop dirty pages tracking on VFIO container + * + * @bcontainer: #VFIOContainerBase on which to de/activate dirty + * pages tracking + * @start: indicates whether to start or stop dirty pages tracking + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, - bool start); + bool start, Error **errp); int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, hwaddr size); diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8bba95ba6a2010b78cae54c6905857686bbb6309..560f4bc38499f7f4a3bc84ef7e4= 184fd6dc89935 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1085,7 +1085,7 @@ static bool vfio_listener_log_global_start(MemoryList= ener *listener, if (vfio_devices_all_device_dirty_tracking(bcontainer)) { ret =3D vfio_devices_dma_logging_start(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, N= ULL); } =20 if (ret) { @@ -1106,7 +1106,7 @@ static bool vfio_listener_log_global_stop(MemoryListe= ner *listener, if (vfio_devices_all_device_dirty_tracking(bcontainer)) { vfio_devices_dma_logging_stop(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = NULL); } =20 if (ret) { diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 913ae49077c4f09b7b27517c1231cfbe4befb7fb..7c0764121d24b02b6c4e66e368d= 7dff78a6d65aa 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -53,14 +53,14 @@ void vfio_container_del_section_window(VFIOContainerBas= e *bcontainer, } =20 int vfio_container_set_dirty_page_tracking(VFIOContainerBase *bcontainer, - bool start) + bool start, Error **errp) { if (!bcontainer->dirty_pages_supported) { return 0; } =20 g_assert(bcontainer->ops->set_dirty_page_tracking); - return bcontainer->ops->set_dirty_page_tracking(bcontainer, start); + return bcontainer->ops->set_dirty_page_tracking(bcontainer, start, err= p); } =20 int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index bd25b9fbad2e717e63c2ab0e331186e5f63cef49..f772ac79b9c413c86d7e60f6dc4= e6699852d5aac 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -210,7 +210,7 @@ static int vfio_legacy_dma_map(const VFIOContainerBase = *bcontainer, hwaddr iova, =20 static int vfio_legacy_set_dirty_page_tracking(const VFIOContainerBase *bcontainer, - bool start) + bool start, Error **errp) { const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, bcontainer); @@ -228,8 +228,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainer= Base *bcontainer, ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty); if (ret) { ret =3D -errno; - error_report("Failed to set dirty tracking flag 0x%x errno: %d", - dirty.flags, errno); + error_setg(errp, "Failed to set dirty tracking flag 0x%x errno: %d= ", + dirty.flags, errno); } =20 return ret; --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066779745431.325510817646; Tue, 27 Feb 2024 12:46:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KY-0005kQ-2T; Tue, 27 Feb 2024 15:45:38 -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 1rf1ov-0004ha-Tj for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:50 -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 1rf1ot-0001Yb-C6 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:49 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkN1l1fz4x0r; Wed, 28 Feb 2024 05:04:44 +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 4TklkK4fYXz4wyy; Wed, 28 Feb 2024 05:04:41 +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?= Subject: [PATCH v2 13/21] vfio: Add Error** argument to vfio_devices_dma_logging_start() Date: Tue, 27 Feb 2024 19:03:37 +0100 Message-ID: <20240227180345.548960-14-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: 1709066780442100010 This allows to update the Error argument of the VFIO log_global_start() handler. Errors detected when device level logging is started will be propagated up to qemu_savevm_state_setup() when the ram save_setup() handler is executed. The vfio_set_migration_error() call becomes redundant. Remove it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 560f4bc38499f7f4a3bc84ef7e4184fd6dc89935..a2d26cd08cb132d2b27c388bd75= db3d9b8128407 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1036,7 +1036,8 @@ static void vfio_device_feature_dma_logging_start_des= troy( g_free(feature); } =20 -static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_start(VFIOContainerBase *bcontainer, + Error **errp) { struct vfio_device_feature *feature; VFIODirtyRanges ranges; @@ -1058,8 +1059,8 @@ static int vfio_devices_dma_logging_start(VFIOContain= erBase *bcontainer) ret =3D ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature); if (ret) { ret =3D -errno; - error_report("%s: Failed to start DMA logging, err %d (%s)", - vbasedev->name, ret, strerror(errno)); + error_setg(errp, "%s: Failed to start DMA logging, err %d (%s)= ", + vbasedev->name, ret, strerror(errno)); goto out; } vbasedev->dirty_tracking =3D true; @@ -1083,15 +1084,13 @@ static bool vfio_listener_log_global_start(MemoryLi= stener *listener, int ret; =20 if (vfio_devices_all_device_dirty_tracking(bcontainer)) { - ret =3D vfio_devices_dma_logging_start(bcontainer); + ret =3D vfio_devices_dma_logging_start(bcontainer, errp); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, N= ULL); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, true, e= rrp); } =20 if (ret) { - error_report("vfio: Could not start dirty page tracking, err: %d (= %s)", - ret, strerror(-ret)); - vfio_set_migration_error(ret); + error_prepend(errp, "vfio: Could not start dirty page tracking - "= ); } return !!ret; } @@ -1106,13 +1105,11 @@ static bool vfio_listener_log_global_stop(MemoryLis= tener *listener, if (vfio_devices_all_device_dirty_tracking(bcontainer)) { vfio_devices_dma_logging_stop(bcontainer); } else { - ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = NULL); + ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = errp); } =20 if (ret) { - error_report("vfio: Could not stop dirty page tracking, err: %d (%= s)", - ret, strerror(-ret)); - vfio_set_migration_error(ret); + error_prepend(errp, "vfio: Could not stop dirty page tracking - "); } return !!ret; } --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066924409875.0034681574039; Tue, 27 Feb 2024 12:48:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kv-00062r-TS; Tue, 27 Feb 2024 15:46: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 1rf1p0-0004vQ-CA for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:54 -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 1rf1ov-0001Yy-DG for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:54 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkR2x2sz4x0q; Wed, 28 Feb 2024 05:04:47 +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 4TklkN5nvFz4wyy; Wed, 28 Feb 2024 05:04:44 +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?= Subject: [PATCH v2 14/21] vfio: Add Error** argument to vfio_devices_dma_logging_stop() Date: Tue, 27 Feb 2024 19:03:38 +0100 Message-ID: <20240227180345.548960-15-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, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=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: 1709066924884100001 This improves error reporting in the log_global_stop() VFIO handler. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index a2d26cd08cb132d2b27c388bd75db3d9b8128407..706e915a3ba5f8520deb3753d9b= b450a986f207a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -938,12 +938,14 @@ static void vfio_dirty_tracking_init(VFIOContainerBas= e *bcontainer, memory_listener_unregister(&dirty.listener); } =20 -static void vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer) +static int vfio_devices_dma_logging_stop(VFIOContainerBase *bcontainer, + Error **errp) { uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature), sizeof(uint64_t))] =3D {}; struct vfio_device_feature *feature =3D (struct vfio_device_feature *)= buf; VFIODevice *vbasedev; + int ret =3D 0; =20 feature->argsz =3D sizeof(buf); feature->flags =3D VFIO_DEVICE_FEATURE_SET | @@ -955,11 +957,17 @@ static void vfio_devices_dma_logging_stop(VFIOContain= erBase *bcontainer) } =20 if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { - warn_report("%s: Failed to stop DMA logging, err %d (%s)", - vbasedev->name, -errno, strerror(errno)); + /* Keep first error */ + if (!ret) { + ret =3D -errno; + error_setg(errp, "%s: Failed to stop DMA logging, err %d (= %s)", + vbasedev->name, -errno, strerror(errno)); + } } vbasedev->dirty_tracking =3D false; } + + return ret; } =20 static struct vfio_device_feature * @@ -1068,7 +1076,8 @@ static int vfio_devices_dma_logging_start(VFIOContain= erBase *bcontainer, =20 out: if (ret) { - vfio_devices_dma_logging_stop(bcontainer); + /* Ignore the potential errors when doing rollback */ + vfio_devices_dma_logging_stop(bcontainer, NULL); } =20 vfio_device_feature_dma_logging_start_destroy(feature); @@ -1103,7 +1112,7 @@ static bool vfio_listener_log_global_stop(MemoryListe= ner *listener, int ret =3D 0; =20 if (vfio_devices_all_device_dirty_tracking(bcontainer)) { - vfio_devices_dma_logging_stop(bcontainer); + ret =3D vfio_devices_dma_logging_stop(bcontainer, errp); } else { ret =3D vfio_container_set_dirty_page_tracking(bcontainer, false, = errp); } --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066778870851.2859025818284; Tue, 27 Feb 2024 12:46:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KX-0005ed-AE; Tue, 27 Feb 2024 15:45: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 1rf1p0-0004wk-PI for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:54 -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-0001ZS-Ip for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:54 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkV45Zzz4x0t; Wed, 28 Feb 2024 05:04:50 +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 4TklkR71bfz4wyy; Wed, 28 Feb 2024 05:04:47 +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?= Subject: [PATCH v2 15/21] vfio: Use new Error** argument in vfio_save_setup() Date: Tue, 27 Feb 2024 19:03:39 +0100 Message-ID: <20240227180345.548960-16-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: 1709066780469100013 Add an Error** argument to vfio_migration_set_state() and adjust callers, including vfio_save_setup(). The error will be propagated up to qemu_savevm_state_setup() where the save_setup() handler is executed. Modify vfio_vmstate_change_prepare() and vfio_vmstate_change() to store a reported error under the migration stream if a migration is in progress. Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 64 ++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 2dfbe671f6f45aa530c7341177bb532d8292cecd..8bdc68c66516710c52443135284= 262580825e0b8 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -84,7 +84,8 @@ static const char *mig_state_to_str(enum vfio_device_mig_= state state) =20 static int vfio_migration_set_state(VFIODevice *vbasedev, enum vfio_device_mig_state new_state, - enum vfio_device_mig_state recover_sta= te) + enum vfio_device_mig_state recover_sta= te, + Error **errp) { VFIOMigration *migration =3D vbasedev->migration; uint64_t buf[DIV_ROUND_UP(sizeof(struct vfio_device_feature) + @@ -104,15 +105,15 @@ static int vfio_migration_set_state(VFIODevice *vbase= dev, ret =3D -errno; =20 if (recover_state =3D=3D VFIO_DEVICE_STATE_ERROR) { - error_report("%s: Failed setting device state to %s, err: %s. " - "Recover state is ERROR. Resetting device", - vbasedev->name, mig_state_to_str(new_state), - strerror(errno)); + error_setg(errp, "%s: Failed setting device state to %s, err: = %s. " + "Recover state is ERROR. Resetting device", + vbasedev->name, mig_state_to_str(new_state), + strerror(errno)); =20 goto reset_device; } =20 - error_report( + error_setg(errp, "%s: Failed setting device state to %s, err: %s. Setting devic= e in recover state %s", vbasedev->name, mig_state_to_str(new_state), strerror(errno), mig_state_to_str(recover_state)); @@ -120,7 +121,7 @@ static int vfio_migration_set_state(VFIODevice *vbasede= v, mig_state->device_state =3D recover_state; if (ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature)) { ret =3D -errno; - error_report( + error_setg(errp, "%s: Failed setting device in recover state, err: %s. Rese= tting device", vbasedev->name, strerror(errno)); =20 @@ -139,7 +140,7 @@ static int vfio_migration_set_state(VFIODevice *vbasede= v, * This can happen if the device is asynchronously reset and * terminates a data transfer. */ - error_report("%s: data_fd out of sync", vbasedev->name); + error_setg(errp, "%s: data_fd out of sync", vbasedev->name); close(mig_state->data_fd); =20 return -EBADF; @@ -170,10 +171,11 @@ reset_device: */ static int vfio_migration_set_state_or_reset(VFIODevice *vbasedev, - enum vfio_device_mig_state new_state) + enum vfio_device_mig_state new_state, + Error **errp) { return vfio_migration_set_state(vbasedev, new_state, - VFIO_DEVICE_STATE_ERROR); + VFIO_DEVICE_STATE_ERROR, errp); } =20 static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev, @@ -391,8 +393,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, E= rror **errp) stop_copy_size); migration->data_buffer =3D g_try_malloc0(migration->data_buffer_size); if (!migration->data_buffer) { - error_report("%s: Failed to allocate migration data buffer", - vbasedev->name); + error_setg(errp, "%s: Failed to allocate migration data buffer", + vbasedev->name); return -ENOMEM; } =20 @@ -402,7 +404,7 @@ static int vfio_save_setup(QEMUFile *f, void *opaque, E= rror **errp) switch (migration->device_state) { case VFIO_DEVICE_STATE_RUNNING: ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_P= RE_COPY, - VFIO_DEVICE_STATE_RUNNING); + VFIO_DEVICE_STATE_RUNNING, errp= ); if (ret) { return ret; } @@ -429,13 +431,20 @@ static void vfio_save_cleanup(void *opaque) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; + Error *local_err =3D NULL; + int ret; =20 /* * Changing device state from STOP_COPY to STOP can take time. Do it h= ere, * after migration has completed, so it won't increase downtime. */ if (migration->device_state =3D=3D VFIO_DEVICE_STATE_STOP_COPY) { - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_STOP= ); + ret =3D vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_STOP, + &local_err); + if (ret) { + error_report_err(local_err); + } } =20 g_free(migration->data_buffer); @@ -541,11 +550,13 @@ static int vfio_save_complete_precopy(QEMUFile *f, vo= id *opaque) VFIODevice *vbasedev =3D opaque; ssize_t data_size; int ret; + Error *local_err =3D NULL; =20 /* We reach here with device state STOP or STOP_COPY only */ ret =3D vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY, - VFIO_DEVICE_STATE_STOP); + VFIO_DEVICE_STATE_STOP, &local_err); if (ret) { + error_report_err(local_err); return ret; } =20 @@ -585,7 +596,7 @@ static int vfio_load_setup(QEMUFile *f, void *opaque, E= rror **errp) VFIODevice *vbasedev =3D opaque; =20 return vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING, - vbasedev->migration->device_state); + vbasedev->migration->device_state, err= p); } =20 static int vfio_load_cleanup(void *opaque) @@ -701,20 +712,22 @@ static void vfio_vmstate_change_prepare(void *opaque,= bool running, VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; enum vfio_device_mig_state new_state; + Error *local_err =3D NULL; int ret; =20 new_state =3D migration->device_state =3D=3D VFIO_DEVICE_STATE_PRE_COP= Y ? VFIO_DEVICE_STATE_PRE_COPY_P2P : VFIO_DEVICE_STATE_RUNNING_P2P; =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state); + ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ if (migrate_get_current()->to_dst_file) { - qemu_file_set_error(migrate_get_current()->to_dst_file, ret); + qemu_file_set_error_obj(migrate_get_current()->to_dst_file, re= t, + local_err); } } =20 @@ -727,6 +740,7 @@ static void vfio_vmstate_change(void *opaque, bool runn= ing, RunState state) { VFIODevice *vbasedev =3D opaque; enum vfio_device_mig_state new_state; + Error *local_err =3D NULL; int ret; =20 if (running) { @@ -739,14 +753,15 @@ static void vfio_vmstate_change(void *opaque, bool ru= nning, RunState state) VFIO_DEVICE_STATE_STOP; } =20 - ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state); + ret =3D vfio_migration_set_state_or_reset(vbasedev, new_state, &local_= err); if (ret) { /* * Migration should be aborted in this case, but vm_state_notify() * currently does not support reporting failures. */ if (migrate_get_current()->to_dst_file) { - qemu_file_set_error(migrate_get_current()->to_dst_file, ret); + qemu_file_set_error_obj(migrate_get_current()->to_dst_file, re= t, + local_err); } } =20 @@ -760,6 +775,8 @@ static void vfio_migration_state_notifier(Notifier *not= ifier, void *data) VFIOMigration *migration =3D container_of(notifier, VFIOMigration, migration_state); VFIODevice *vbasedev =3D migration->vbasedev; + Error *local_err =3D NULL; + int ret; =20 trace_vfio_migration_state_notifier(vbasedev->name, MigrationStatus_str(s->state)); @@ -768,7 +785,12 @@ static void vfio_migration_state_notifier(Notifier *no= tifier, void *data) case MIGRATION_STATUS_CANCELLING: case MIGRATION_STATUS_CANCELLED: case MIGRATION_STATUS_FAILED: - vfio_migration_set_state_or_reset(vbasedev, VFIO_DEVICE_STATE_RUNN= ING); + ret =3D vfio_migration_set_state_or_reset(vbasedev, + VFIO_DEVICE_STATE_RUNNING, + &local_err); + if (ret) { + error_report_err(local_err); + } } } =20 --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066815986907.2205527809657; Tue, 27 Feb 2024 12:46:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kv-000623-3s; Tue, 27 Feb 2024 15:46: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 1rf1p6-00059Z-25 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:00 -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 1rf1p1-0001Zi-RZ for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:04:59 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4TklkY5QS3z4x1H; Wed, 28 Feb 2024 05:04:53 +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 4TklkW1DVjz4wyy; Wed, 28 Feb 2024 05:04:50 +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?= Subject: [PATCH v2 16/21] vfio: Add Error** argument to .vfio_save_config() handler Date: Tue, 27 Feb 2024 19:03:40 +0100 Message-ID: <20240227180345.548960-17-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: 1709066816533100001 Use vmstate_save_state_with_err() to improve error reporting in the callers and store a reported error under the migration stream. Add documentation while at it. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 25 ++++++++++++++++++++++++- hw/vfio/migration.c | 18 ++++++++++++------ hw/vfio/pci.c | 5 +++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 9b7ef7d02b5a0ad5266bcc4d06cd6874178978e4..6d9dee626afc491645d2c2398f3= e3210961f67e9 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -133,7 +133,30 @@ struct VFIODeviceOps { int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); - void (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f); + + /** + * @vfio_save_config + * + * Save device config state + * + * @vdev: #VFIODevice for which to save the config + * @f: #QEMUFile where to send the data + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ + int (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f, Error **errp); + + /** + * @vfio_load_config + * + * Load device config state + * + * @vdev: #VFIODevice for which to load the config + * @f: #QEMUFile where to get the data + * + * Returns zero to indicate success and negative for error + */ int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 8bdc68c66516710c52443135284262580825e0b8..228e8854594f3714b7c6f4fcfc5= 468d6b56337cb 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -190,14 +190,19 @@ static int vfio_load_buffer(QEMUFile *f, VFIODevice *= vbasedev, return ret; } =20 -static int vfio_save_device_config_state(QEMUFile *f, void *opaque) +static int vfio_save_device_config_state(QEMUFile *f, void *opaque, + Error **errp) { VFIODevice *vbasedev =3D opaque; + int ret; =20 qemu_put_be64(f, VFIO_MIG_FLAG_DEV_CONFIG_STATE); =20 if (vbasedev->ops && vbasedev->ops->vfio_save_config) { - vbasedev->ops->vfio_save_config(vbasedev, f); + ret =3D vbasedev->ops->vfio_save_config(vbasedev, f, errp); + if (ret) { + return ret; + } } =20 qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); @@ -581,13 +586,14 @@ static int vfio_save_complete_precopy(QEMUFile *f, vo= id *opaque) static void vfio_save_state(QEMUFile *f, void *opaque) { VFIODevice *vbasedev =3D opaque; + Error *local_err =3D NULL; int ret; =20 - ret =3D vfio_save_device_config_state(f, opaque); + ret =3D vfio_save_device_config_state(f, opaque, &local_err); if (ret) { - error_report("%s: Failed to save device config space", - vbasedev->name); - qemu_file_set_error(f, ret); + error_prepend(&local_err, "%s: Failed to save device config space", + vbasedev->name); + qemu_file_set_error_obj(f, ret, local_err); } } =20 diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 4fa387f0430d62ca2ba1b5ae5b7037f8f06b33f9..99d86e1d40ef25133fc76ad6e58= 294b07bd20843 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2585,11 +2585,12 @@ const VMStateDescription vmstate_vfio_pci_config = =3D { } }; =20 -static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f) +static int vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f, Error *= *errp) { VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); =20 - vmstate_save_state(f, &vmstate_vfio_pci_config, vdev, NULL); + return vmstate_save_state_with_err(f, &vmstate_vfio_pci_config, vdev, = NULL, + errp); } =20 static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066874145507.65784828397693; Tue, 27 Feb 2024 12:47:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KY-0005lb-9x; Tue, 27 Feb 2024 15:45:38 -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 1rf1p6-0005C9-Tv for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:00 -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 1rf1p4-0001a0-Si for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:00 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklkc6dwBz4x1R; Wed, 28 Feb 2024 05:04:56 +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 4TklkZ2NvLz4wyy; Wed, 28 Feb 2024 05:04:54 +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?= Subject: [PATCH v2 17/21] vfio: Reverse test on vfio_get_dirty_bitmap() Date: Tue, 27 Feb 2024 19:03:41 +0100 Message-ID: <20240227180345.548960-18-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-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: 1709066874679100001 It will simplify the changes coming after. Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 706e915a3ba5f8520deb3753d9bb450a986f207a..e51757e7d747c60b67deb966bb2= 9b946a511b328 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1237,16 +1237,20 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) } =20 rcu_read_lock(); - if (vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { - ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask += 1, - translated_addr); - if (ret) { - error_report("vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx"= , " - "0x%"HWADDR_PRIx") =3D %d (%s)", - bcontainer, iova, iotlb->addr_mask + 1, ret, - strerror(-ret)); - } + if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { + goto out_lock; } + + ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, + translated_addr); + if (ret) { + error_report("vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") =3D %d (%s)", + bcontainer, iova, iotlb->addr_mask + 1, ret, + strerror(-ret)); + } + +out_lock: rcu_read_unlock(); =20 out: --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066883130909.1068840444067; Tue, 27 Feb 2024 12:48:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4KW-0005aO-D9; Tue, 27 Feb 2024 15:45:36 -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 1rf1pB-0005Lt-Bp for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:05 -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 1rf1p9-0001af-4S for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:05 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklkh6wkGz4x1d; Wed, 28 Feb 2024 05:05:00 +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 4Tklkd3cpGz4x1Y; Wed, 28 Feb 2024 05:04:57 +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?= , "Michael S . Tsirkin" , Paolo Bonzini , David Hildenbrand Subject: [PATCH v2 18/21] memory: Add Error** argument to memory_get_xlat_addr() Date: Tue, 27 Feb 2024 19:03:42 +0100 Message-ID: <20240227180345.548960-19-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: 1709066884795100004 Let the callers do the reporting. This will be useful in vfio_iommu_map_dirty_notify(). Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: David Hildenbrand Signed-off-by: C=C3=A9dric Le Goater --- include/exec/memory.h | 15 ++++++++++++++- hw/vfio/common.c | 13 +++++++++---- hw/virtio/vhost-vdpa.c | 5 ++++- system/memory.c | 10 +++++----- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 8b019465ab13ce85c03075c80865a0865ea1feed..baca989023415b69be3b4b4e7a6= 22f983182314b 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -771,9 +771,22 @@ void ram_discard_manager_register_listener(RamDiscardM= anager *rdm, void ram_discard_manager_unregister_listener(RamDiscardManager *rdm, RamDiscardListener *rdl); =20 +/** + * memory_get_xlat_addr: Extract addresses from a TLB entry + * + * @iotlb: pointer to an #IOMMUTLBEntry + * @vaddr: virtual addressf + * @ram_addr: RAM address + * @read_only: indicates if writes are allowed + * @mr_has_discard_manager: indicates memory is controlled by a + * RamDiscardManager + * @errp: pointer to Error*, to store an error if it happens. + * + * Return: true on success, else false setting @errp with error. + */ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, ram_addr_t *ram_addr, bool *read_only, - bool *mr_has_discard_manager); + bool *mr_has_discard_manager, Error **errp); =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; typedef struct MemoryRegionIoeventfd MemoryRegionIoeventfd; diff --git a/hw/vfio/common.c b/hw/vfio/common.c index e51757e7d747c60b67deb966bb29b946a511b328..43f37447e3692ffa97788b02f83= b81b44aaf301a 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -262,12 +262,13 @@ static bool vfio_listener_skipped_section(MemoryRegio= nSection *section) =20 /* Called with rcu_read_lock held. */ static bool vfio_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, - ram_addr_t *ram_addr, bool *read_only) + ram_addr_t *ram_addr, bool *read_only, + Error **errp) { bool ret, mr_has_discard_manager; =20 ret =3D memory_get_xlat_addr(iotlb, vaddr, ram_addr, read_only, - &mr_has_discard_manager); + &mr_has_discard_manager, errp); if (ret && mr_has_discard_manager) { /* * Malicious VMs might trigger discarding of IOMMU-mapped memory. = The @@ -297,6 +298,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) hwaddr iova =3D iotlb->iova + giommu->iommu_offset; void *vaddr; int ret; + Error *local_err =3D NULL; =20 trace_vfio_iommu_map_notify(iotlb->perm =3D=3D IOMMU_NONE ? "UNMAP" : = "MAP", iova, iova + iotlb->addr_mask); @@ -313,7 +315,8 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { bool read_only; =20 - if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { + if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, &local_er= r)) { + error_report_err(local_err); goto out; } /* @@ -1226,6 +1229,7 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) VFIOContainerBase *bcontainer =3D giommu->bcontainer; hwaddr iova =3D iotlb->iova + giommu->iommu_offset; ram_addr_t translated_addr; + Error *local_err =3D NULL; int ret =3D -EINVAL; =20 trace_vfio_iommu_map_dirty_notify(iova, iova + iotlb->addr_mask); @@ -1237,7 +1241,8 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) } =20 rcu_read_lock(); - if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL)) { + if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL, &local_er= r)) { + error_report_err(local_err); goto out_lock; } =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ddae494ca8e8154ce03b88bc781fe9f1e639aceb..a6f06266cfc798b20b98001fa97= ce771722175ec 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -203,6 +203,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) void *vaddr; int ret; Int128 llend; + Error *local_err =3D NULL; =20 if (iotlb->target_as !=3D &address_space_memory) { error_report("Wrong target AS \"%s\", only system memory is allowe= d", @@ -222,7 +223,9 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { bool read_only; =20 - if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL)) { + if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL, + &local_err)) { + error_report_err(local_err); return; } ret =3D vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova, diff --git a/system/memory.c b/system/memory.c index 48aed0f8ece1c731849636c442b8ab8e5d7ff6a5..132c026e35cbeb0ab8fa0fe64bb= 9db50f6024e0d 100644 --- a/system/memory.c +++ b/system/memory.c @@ -2203,7 +2203,7 @@ void ram_discard_manager_unregister_listener(RamDisca= rdManager *rdm, /* Called with rcu_read_lock held. */ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, ram_addr_t *ram_addr, bool *read_only, - bool *mr_has_discard_manager) + bool *mr_has_discard_manager, Error **errp) { MemoryRegion *mr; hwaddr xlat; @@ -2221,7 +2221,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, mr =3D address_space_translate(&address_space_memory, iotlb->translate= d_addr, &xlat, &len, writable, MEMTXATTRS_UNSPECI= FIED); if (!memory_region_is_ram(mr)) { - error_report("iommu map to non memory area %" HWADDR_PRIx "", xlat= ); + error_setg(errp, "iommu map to non memory area %" HWADDR_PRIx "", = xlat); return false; } else if (memory_region_has_ram_discard_manager(mr)) { RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(m= r); @@ -2240,8 +2240,8 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, * were already restored before IOMMUs are restored. */ if (!ram_discard_manager_is_populated(rdm, &tmp)) { - error_report("iommu map to discarded memory (e.g., unplugged v= ia" - " virtio-mem): %" HWADDR_PRIx "", + error_setg(errp, "iommu map to discarded memory (e.g., unplugg= ed" + " via virtio-mem): %" HWADDR_PRIx "", iotlb->translated_addr); return false; } @@ -2252,7 +2252,7 @@ bool memory_get_xlat_addr(IOMMUTLBEntry *iotlb, void = **vaddr, * check that it did not truncate too much. */ if (len & iotlb->addr_mask) { - error_report("iommu has granularity incompatible with target AS"); + error_setg(errp, "iommu has granularity incompatible with target A= S"); return false; } =20 --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066870410903.9120719868857; Tue, 27 Feb 2024 12:47:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kt-0005xu-KD; Tue, 27 Feb 2024 15:45: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 1rf1pG-0005RI-OM for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:12 -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 1rf1pC-0001mJ-4v for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:09 -0500 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklkm10Trz4x1k; Wed, 28 Feb 2024 05:05:04 +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 4Tklkj3rxMz4x1Y; Wed, 28 Feb 2024 05:05:01 +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?= Subject: [PATCH v2 19/21] vfio: Add Error** argument to .get_dirty_bitmap() handler Date: Tue, 27 Feb 2024 19:03:43 +0100 Message-ID: <20240227180345.548960-20-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: 1709066870735100001 Let the callers do the error reporting. Add documentation while at it. Signed-off-by: C=C3=A9dric Le Goater --- include/hw/vfio/vfio-common.h | 4 +- include/hw/vfio/vfio-container-base.h | 17 +++++++- hw/vfio/common.c | 59 ++++++++++++++++++--------- hw/vfio/container-base.c | 5 ++- hw/vfio/container.c | 13 +++--- 5 files changed, 67 insertions(+), 31 deletions(-) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 6d9dee626afc491645d2c2398f3e3210961f67e9..83ffad89f5cf434452332fe29fb= 752d9ec71b2f0 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -271,9 +271,9 @@ bool vfio_devices_all_device_dirty_tracking(const VFIOContainerBase *bcontainer= ); int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, - hwaddr size); + hwaddr size, Error **errp); int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr); + uint64_t size, ram_addr_t ram_addr, Error **errp= ); =20 /* Returns 0 on success, or a negative errno. */ int vfio_device_get_name(VFIODevice *vbasedev, Error **errp); diff --git a/include/hw/vfio/vfio-container-base.h b/include/hw/vfio/vfio-c= ontainer-base.h index dec2023eceb6c7d62b0ee35008cc58f8e695e190..3ee713014cb414f18b34092641a= 17717983b5559 100644 --- a/include/hw/vfio/vfio-container-base.h +++ b/include/hw/vfio/vfio-container-base.h @@ -84,7 +84,7 @@ int vfio_container_set_dirty_page_tracking(VFIOContainerB= ase *bcontainer, bool start, Error **errp); int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + hwaddr iova, hwaddr size, Error **er= rp); =20 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *space, @@ -137,9 +137,22 @@ struct VFIOIOMMUClass { */ int (*set_dirty_page_tracking)(const VFIOContainerBase *bcontainer, bool start, Error **errp); + /** + * @query_dirty_bitmap + * + * Get list of dirty pages from container + * + * @bcontainer: #VFIOContainerBase from which to get dirty pages + * @vbmap: #VFIOBitmap internal bitmap structure + * @iova: iova base address + * @size: size of iova range + * @errp: pointer to Error*, to store an error if it happens. + * + * Returns zero to indicate success and negative for error + */ int (*query_dirty_bitmap)(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, - hwaddr iova, hwaddr size); + hwaddr iova, hwaddr size, Error **errp); /* PCI specific */ int (*pci_hot_reset)(VFIODevice *vbasedev, bool single); =20 diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 43f37447e3692ffa97788b02f83b81b44aaf301a..8fbf04e55d1b304bc80fdd9ef6f= 5f5089acd3360 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1154,7 +1154,7 @@ static int vfio_device_dma_logging_report(VFIODevice = *vbasedev, hwaddr iova, =20 int vfio_devices_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, hwaddr iova, - hwaddr size) + hwaddr size, Error **errp) { VFIODevice *vbasedev; int ret; @@ -1163,10 +1163,10 @@ int vfio_devices_query_dirty_bitmap(const VFIOConta= inerBase *bcontainer, ret =3D vfio_device_dma_logging_report(vbasedev, iova, size, vbmap->bitmap); if (ret) { - error_report("%s: Failed to get DMA logging report, iova: " - "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx - ", err: %d (%s)", - vbasedev->name, iova, size, ret, strerror(-ret)); + error_setg(errp, "%s: Failed to get DMA logging report, iova: " + "0x%" HWADDR_PRIx ", size: 0x%" HWADDR_PRIx + ", err: %d (%s)", + vbasedev->name, iova, size, ret, strerror(-ret)); =20 return ret; } @@ -1176,7 +1176,7 @@ int vfio_devices_query_dirty_bitmap(const VFIOContain= erBase *bcontainer, } =20 int vfio_get_dirty_bitmap(const VFIOContainerBase *bcontainer, uint64_t io= va, - uint64_t size, ram_addr_t ram_addr) + uint64_t size, ram_addr_t ram_addr, Error **errp) { bool all_device_dirty_tracking =3D vfio_devices_all_device_dirty_tracking(bcontainer); @@ -1193,13 +1193,17 @@ int vfio_get_dirty_bitmap(const VFIOContainerBase *= bcontainer, uint64_t iova, =20 ret =3D vfio_bitmap_alloc(&vbmap, size); if (ret) { + error_setg_errno(errp, -ret, + "Failed to allocate dirty tracking bitmap"); return ret; } =20 if (all_device_dirty_tracking) { - ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size); + ret =3D vfio_devices_query_dirty_bitmap(bcontainer, &vbmap, iova, = size, + errp); } else { - ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size); + ret =3D vfio_container_query_dirty_bitmap(bcontainer, &vbmap, iova= , size, + errp); } =20 if (ret) { @@ -1247,12 +1251,13 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) } =20 ret =3D vfio_get_dirty_bitmap(bcontainer, iova, iotlb->addr_mask + 1, - translated_addr); + translated_addr, &local_err); if (ret) { - error_report("vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") =3D %d (%s)", - bcontainer, iova, iotlb->addr_mask + 1, ret, - strerror(-ret)); + error_prepend(&local_err, + "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") failed :", bcontainer, iova, + iotlb->addr_mask + 1); + error_report_err(local_err); } =20 out_lock: @@ -1272,12 +1277,19 @@ static int vfio_ram_discard_get_dirty_bitmap(Memory= RegionSection *section, const ram_addr_t ram_addr =3D memory_region_get_ram_addr(section->mr) + section->offset_within_region; VFIORamDiscardListener *vrdl =3D opaque; + Error *local_err =3D NULL; + int ret; =20 /* * Sync the whole mapped region (spanning multiple individual mappings) * in one go. */ - return vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr); + ret =3D vfio_get_dirty_bitmap(vrdl->bcontainer, iova, size, ram_addr, + &local_err); + if (ret) { + error_report_err(local_err); + } + return ret; } =20 static int @@ -1309,7 +1321,7 @@ vfio_sync_ram_discard_listener_dirty_bitmap(VFIOConta= inerBase *bcontainer, } =20 static int vfio_sync_dirty_bitmap(VFIOContainerBase *bcontainer, - MemoryRegionSection *section) + MemoryRegionSection *section, Error **er= rp) { ram_addr_t ram_addr; =20 @@ -1340,7 +1352,14 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase = *bcontainer, } return 0; } else if (memory_region_has_ram_discard_manager(section->mr)) { - return vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, sec= tion); + int ret; + + ret =3D vfio_sync_ram_discard_listener_dirty_bitmap(bcontainer, se= ction); + if (ret) { + error_setg(errp, + "Failed to sync dirty bitmap with RAM discard liste= ner"); + return ret; + } } =20 ram_addr =3D memory_region_get_ram_addr(section->mr) + @@ -1348,7 +1367,7 @@ static int vfio_sync_dirty_bitmap(VFIOContainerBase *= bcontainer, =20 return vfio_get_dirty_bitmap(bcontainer, REAL_HOST_PAGE_ALIGN(section->offset_within_address_spa= ce), - int128_get64(section->size), ram_addr); + int128_get64(section->size), ram_addr, er= rp); } =20 static void vfio_listener_log_sync(MemoryListener *listener, @@ -1357,16 +1376,16 @@ static void vfio_listener_log_sync(MemoryListener *= listener, VFIOContainerBase *bcontainer =3D container_of(listener, VFIOContainer= Base, listener); int ret; + Error *local_err =3D NULL; =20 if (vfio_listener_skipped_section(section)) { return; } =20 if (vfio_devices_all_dirty_tracking(bcontainer)) { - ret =3D vfio_sync_dirty_bitmap(bcontainer, section); + ret =3D vfio_sync_dirty_bitmap(bcontainer, section, &local_err); if (ret) { - error_report("vfio: Failed to sync dirty bitmap, err: %d (%s)"= , ret, - strerror(-ret)); + error_report_err(local_err); vfio_set_migration_error(ret); } } diff --git a/hw/vfio/container-base.c b/hw/vfio/container-base.c index 7c0764121d24b02b6c4e66e368d7dff78a6d65aa..8db59881873c3b1edee81104b96= 6af737e5fa6f6 100644 --- a/hw/vfio/container-base.c +++ b/hw/vfio/container-base.c @@ -65,10 +65,11 @@ int vfio_container_set_dirty_page_tracking(VFIOContaine= rBase *bcontainer, =20 int vfio_container_query_dirty_bitmap(const VFIOContainerBase *bcontainer, VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + hwaddr iova, hwaddr size, Error **er= rp) { g_assert(bcontainer->ops->query_dirty_bitmap); - return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, si= ze); + return bcontainer->ops->query_dirty_bitmap(bcontainer, vbmap, iova, si= ze, + errp); } =20 void vfio_container_init(VFIOContainerBase *bcontainer, VFIOAddressSpace *= space, diff --git a/hw/vfio/container.c b/hw/vfio/container.c index f772ac79b9c413c86d7e60f6dc4e6699852d5aac..a5243b5ee4bb5bc2f732554bd6c= fa1b92758195e 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -131,6 +131,7 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, }; bool need_dirty_sync =3D false; int ret; + Error *local_err =3D NULL; =20 if (iotlb && vfio_devices_all_running_and_mig_active(bcontainer)) { if (!vfio_devices_all_device_dirty_tracking(bcontainer) && @@ -166,8 +167,9 @@ static int vfio_legacy_dma_unmap(const VFIOContainerBas= e *bcontainer, =20 if (need_dirty_sync) { ret =3D vfio_get_dirty_bitmap(bcontainer, iova, size, - iotlb->translated_addr); + iotlb->translated_addr, &local_err); if (ret) { + error_report_err(local_err); return ret; } } @@ -237,7 +239,8 @@ vfio_legacy_set_dirty_page_tracking(const VFIOContainer= Base *bcontainer, =20 static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontai= ner, VFIOBitmap *vbmap, - hwaddr iova, hwaddr size) + hwaddr iova, hwaddr size, + Error **errp) { const VFIOContainer *container =3D container_of(bcontainer, VFIOContai= ner, bcontainer); @@ -265,9 +268,9 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOCon= tainerBase *bcontainer, ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap); if (ret) { ret =3D -errno; - error_report("Failed to get dirty bitmap for iova: 0x%"PRIx64 - " size: 0x%"PRIx64" err: %d", (uint64_t)range->iova, - (uint64_t)range->size, errno); + error_setg(errp, "Failed to get dirty bitmap for iova: 0x%"PRIx64 + " size: 0x%"PRIx64" err: %d", (uint64_t)range->iova, + (uint64_t)range->size, errno); } =20 g_free(dbitmap); --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 170906680431056.486877840927605; Tue, 27 Feb 2024 12:46:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Kh-0005ty-5T; Tue, 27 Feb 2024 15:45:53 -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 1rf1pK-0005UB-Fi for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:16 -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 1rf1pG-0001oS-G7 for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:13 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklkq2dCLz4x1c; Wed, 28 Feb 2024 05:05:07 +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 4Tklkm54jZz4x1Y; Wed, 28 Feb 2024 05:05:04 +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?= Subject: [PATCH v2 20/21] vfio: Also trace event failures in vfio_save_complete_precopy() Date: Tue, 27 Feb 2024 19:03:44 +0100 Message-ID: <20240227180345.548960-21-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=2404:9400:2221:ea00::3; envelope-from=SRS0=GitP=KE=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.249, 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-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: 1709066804483100001 vfio_save_complete_precopy() currently returns before doing the trace event. Change that. Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/migration.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 228e8854594f3714b7c6f4fcfc5468d6b56337cb..f3b500dd1cab944722ccbc41575= b15046c2420c9 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -574,9 +574,6 @@ static int vfio_save_complete_precopy(QEMUFile *f, void= *opaque) =20 qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); ret =3D qemu_file_get_error(f); - if (ret) { - return ret; - } =20 trace_vfio_save_complete_precopy(vbasedev->name, ret); =20 --=20 2.43.2 From nobody Tue Nov 26 07:52:36 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 1709066928958126.49382307837845; Tue, 27 Feb 2024 12:48:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rf4Ku-00060b-DS; 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 1rf1pS-0005Yx-8g for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:28 -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 1rf1pK-0001p1-4H for qemu-devel@nongnu.org; Tue, 27 Feb 2024 13:05:20 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4Tklkt3rFtz4wb2; Wed, 28 Feb 2024 05:05:10 +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 4Tklkq6k1Vz4x1R; Wed, 28 Feb 2024 05:05:07 +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?= Subject: [PATCH v2 21/21] vfio: Extend vfio_set_migration_error() with Error* argument Date: Tue, 27 Feb 2024 19:03:45 +0100 Message-ID: <20240227180345.548960-22-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: 1709066930896100003 vfio_set_migration_error() sets the 'return' error on the migration stream if a migration is in progress. To improve error reporting, add a new Error* argument to also set the Error object on the migration stream, if a migration is progress. Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/common.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 8fbf04e55d1b304bc80fdd9ef6f5f5089acd3360..5e6353ae468c885af0fa169b671= 902a518df4c75 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -148,16 +148,18 @@ bool vfio_viommu_preset(VFIODevice *vbasedev) return vbasedev->bcontainer->space->as !=3D &address_space_memory; } =20 -static void vfio_set_migration_error(int err) +static void vfio_set_migration_error(int ret, Error *err) { MigrationState *ms =3D migrate_get_current(); =20 if (migration_is_setup_or_active(ms->state)) { WITH_QEMU_LOCK_GUARD(&ms->qemu_file_lock) { if (ms->to_dst_file) { - qemu_file_set_error(ms->to_dst_file, err); + qemu_file_set_error_obj(ms->to_dst_file, ret, err); } } + } else { + error_report_err(err); } } =20 @@ -304,9 +306,10 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IO= MMUTLBEntry *iotlb) iova, iova + iotlb->addr_mask); =20 if (iotlb->target_as !=3D &address_space_memory) { - error_report("Wrong target AS \"%s\", only system memory is allowe= d", - iotlb->target_as->name ? iotlb->target_as->name : "no= ne"); - vfio_set_migration_error(-EINVAL); + error_setg(&local_err, + "Wrong target AS \"%s\", only system memory is allowed", + iotlb->target_as->name ? iotlb->target_as->name : "none= "); + vfio_set_migration_error(-EINVAL, local_err); return; } =20 @@ -339,11 +342,12 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, I= OMMUTLBEntry *iotlb) ret =3D vfio_container_dma_unmap(bcontainer, iova, iotlb->addr_mask + 1, iotlb); if (ret) { - error_report("vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", " - "0x%"HWADDR_PRIx") =3D %d (%s)", - bcontainer, iova, - iotlb->addr_mask + 1, ret, strerror(-ret)); - vfio_set_migration_error(ret); + error_setg(&local_err, + "vfio_container_dma_unmap(%p, 0x%"HWADDR_PRIx", " + "0x%"HWADDR_PRIx") =3D %d (%s)", + bcontainer, iova, + iotlb->addr_mask + 1, ret, strerror(-ret)); + vfio_set_migration_error(ret, local_err); } } out: @@ -1239,14 +1243,14 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifi= er *n, IOMMUTLBEntry *iotlb) trace_vfio_iommu_map_dirty_notify(iova, iova + iotlb->addr_mask); =20 if (iotlb->target_as !=3D &address_space_memory) { - error_report("Wrong target AS \"%s\", only system memory is allowe= d", - iotlb->target_as->name ? iotlb->target_as->name : "no= ne"); + error_setg(&local_err, + "Wrong target AS \"%s\", only system memory is allowed", + iotlb->target_as->name ? iotlb->target_as->name : "none= "); goto out; } =20 rcu_read_lock(); if (!vfio_get_xlat_addr(iotlb, NULL, &translated_addr, NULL, &local_er= r)) { - error_report_err(local_err); goto out_lock; } =20 @@ -1257,7 +1261,6 @@ static void vfio_iommu_map_dirty_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) "vfio_iommu_map_dirty_notify(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") failed :", bcontainer, iova, iotlb->addr_mask + 1); - error_report_err(local_err); } =20 out_lock: @@ -1265,7 +1268,7 @@ out_lock: =20 out: if (ret) { - vfio_set_migration_error(ret); + vfio_set_migration_error(ret, local_err); } } =20 @@ -1385,8 +1388,7 @@ static void vfio_listener_log_sync(MemoryListener *li= stener, if (vfio_devices_all_dirty_tracking(bcontainer)) { ret =3D vfio_sync_dirty_bitmap(bcontainer, section, &local_err); if (ret) { - error_report_err(local_err); - vfio_set_migration_error(ret); + vfio_set_migration_error(ret, local_err); } } } --=20 2.43.2