From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354192; cv=none; d=zohomail.com; s=zohoarc; b=T3T9mlKHTFOvL47AKhiYdpmSffm0HjbzcbOL/T3dvVD+anzndQbbglXBlc0T1mPFFEl1E1X2tmuz3BLJaVRGomb1IXNFgHa+/dVR0TcNCpFQbHPJiB/TYNhgxNrherVi2DOHNeGVsw8AxxUZiM2mWi40pxYrGauerGJmwZTHcyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354192; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4tyAthjyAJfKR2wxZiLS098ns/1BTHiWpLuviegbRVQ=; b=DD2GgteLjafclbaj4DKUlb78M+6bLOPJsmEFKdL68BkUOQPlJb90CZZS4nl074njweKoLF3cGw7gESmJvLgVLX88XRQywV4cW2kXSCXtBFc0tZeOHH47sUazOqI4N9uFnIEoQ+37U76swZ6GRPw8mW0shfyyzYk7AgtuAmAJWXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16753541921651019.6006574194643; Thu, 2 Feb 2023 08:09:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7f-0007Fx-Qv; Thu, 02 Feb 2023 11:07: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 1pNc7D-00073M-Uy for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc78-0004zw-SJ for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:09 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-549-L3xXIx-LNb2s_CSQm-VjVA-1; Thu, 02 Feb 2023 11:07:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7AB593C4220D; Thu, 2 Feb 2023 16:06:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94F6E51E5; Thu, 2 Feb 2023 16:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354026; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4tyAthjyAJfKR2wxZiLS098ns/1BTHiWpLuviegbRVQ=; b=Y4sJ1Rv17oE47f80CAc/AiH298w1h823ueUlCMSxbxbeMAfijtSCPwIwdU+EaJowyQaa+O xk9nBHCkyjVNWqsCcFsACr+G2DCIwUGDRtz/9SsW/Ew9LXuPQIIIhB+7A8F9+A/D1pTkJz kgonpgVuo7Es2sX+wyB4XtklUFvsCQk= X-MC-Unique: L3xXIx-LNb2s_CSQm-VjVA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu , qemu-stable@nongnu.org Subject: [PULL 01/26] migration: Fix migration crash when target psize larger than host Date: Thu, 2 Feb 2023 17:06:15 +0100 Message-Id: <20230202160640.2300-2-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354193886100004 Content-Type: text/plain; charset="utf-8" From: Peter Xu Commit d9e474ea56 overlooked the case where the target psize is even larger than the host psize. One example is Alpha has 8K page size and migration will start to crash the source QEMU when running Alpha migration on x86. Fix it by detecting that case and set host start/end just to cover the single page to be migrated. This will slightly optimize the common case where host psize equals to guest psize so we don't even need to do the roundups, but that's trivial. Cc: qemu-stable@nongnu.org Reported-by: Thomas Huth Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1456 Fixes: d9e474ea56 ("migration: Teach PSS about host page") Signed-off-by: Peter Xu Reviewed-by: Thomas Huth Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 334309f1c6..68a45338e3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2319,8 +2319,25 @@ static void pss_host_page_prepare(PageSearchStatus *= pss) size_t guest_pfns =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BIT= S; =20 pss->host_page_sending =3D true; - pss->host_page_start =3D ROUND_DOWN(pss->page, guest_pfns); - pss->host_page_end =3D ROUND_UP(pss->page + 1, guest_pfns); + if (guest_pfns <=3D 1) { + /* + * This covers both when guest psize =3D=3D host psize, or when gu= est + * has larger psize than the host (guest_pfns=3D=3D0). + * + * For the latter, we always send one whole guest page per + * iteration of the host page (example: an Alpha VM on x86 host + * will have guest psize 8K while host psize 4K). + */ + pss->host_page_start =3D pss->page; + pss->host_page_end =3D pss->page + 1; + } else { + /* + * The host page spans over multiple guest pages, we send them + * within the same host page iteration. + */ + pss->host_page_start =3D ROUND_DOWN(pss->page, guest_pfns); + pss->host_page_end =3D ROUND_UP(pss->page + 1, guest_pfns); + } } =20 /* --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354126; cv=none; d=zohomail.com; s=zohoarc; b=LLk9nS4dBhVVCOZ8YYiqAzNEFozAYHZMV/GEJ4QmaPUyN0efi/wx2Mt2QtyHtNYzc1RZ7A6V/nhFxSpm8MWD7cfMlpnj0pxxOae0reIaSEu0K5ATz0rvpZ32iPnrUO3dree9edtXY7Pprj7sWKiYU2zPdcO1ja74gSjH3m+eDmo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354126; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oX5tblJaN6DhtUONVwtbCE80ZM9W0Q9shTGTQafbQv8=; b=D08Yw1SNXq2eSpDK5uCDNuNBONFLgy9qBlBBvj7kdxTdGoEabmjSKswA9N2Ybj0Mbxo5yYUmZs3BuZzu7q5As3WszOsumw6X50bynxx6RKIqJKEj+18ubB7Vq4Cye73VwTREnnnj5bS60tU2hpmMBsVnozfBMOqUF6FCrgP85f4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354126255297.85472987470644; Thu, 2 Feb 2023 08:08:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7g-0007HL-3p; Thu, 02 Feb 2023 11:07:40 -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 1pNc7D-00073K-UQ for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:12 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc78-0004zk-VD for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:09 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-663-yHx7284pOY23S6AuubuQtQ-1; Thu, 02 Feb 2023 11:06:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EA7218E092B; Thu, 2 Feb 2023 16:06:56 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id C195551E5; Thu, 2 Feb 2023 16:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354025; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oX5tblJaN6DhtUONVwtbCE80ZM9W0Q9shTGTQafbQv8=; b=QayiOpWc2ud4+5xlXi0TPmP4vBLNU8KYVqqq87GJC4jV45cnmiLgu6YM2zOUi33283lLrV xuLxKoHF4mT4VYsdPBSLfAoORxMjalZ92vGU64Vf9hkLHSDwaGX8lDYIXDyA+X/7o04K1U CD+YTGa+uqBCzvyINPmyyz+g+trsxvc= X-MC-Unique: yHx7284pOY23S6AuubuQtQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org Subject: [PULL 02/26] migration: No save_live_pending() method uses the QEMUFile parameter Date: Thu, 2 Feb 2023 17:06:16 +0100 Message-Id: <20230202160640.2300-3-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354127328100001 Content-Type: text/plain; charset="utf-8" So remove it everywhere. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- include/migration/register.h | 2 +- migration/savevm.h | 2 +- hw/s390x/s390-stattrib.c | 2 +- hw/vfio/migration.c | 2 +- migration/block-dirty-bitmap.c | 2 +- migration/block.c | 2 +- migration/migration.c | 2 +- migration/ram.c | 2 +- migration/savevm.c | 4 ++-- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index c1dcff0f90..6ca71367af 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -46,7 +46,7 @@ typedef struct SaveVMHandlers { =20 /* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f, void *opaque); - void (*save_live_pending)(QEMUFile *f, void *opaque, + void (*save_live_pending)(void *opaque, uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, diff --git a/migration/savevm.h b/migration/savevm.h index 6461342cb4..524cf12f25 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -40,7 +40,7 @@ void qemu_savevm_state_cleanup(void); void qemu_savevm_state_complete_postcopy(QEMUFile *f); int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, bool inactivate_disks); -void qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size, +void qemu_savevm_state_pending(uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only); diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index 9eda1c3b2a..a553a1e850 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -182,7 +182,7 @@ static int cmma_save_setup(QEMUFile *f, void *opaque) return 0; } =20 -static void cmma_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, +static void cmma_save_pending(void *opaque, uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index c74453e0b5..b2125c7607 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -456,7 +456,7 @@ static void vfio_save_cleanup(void *opaque) trace_vfio_save_cleanup(vbasedev->name); } =20 -static void vfio_save_pending(QEMUFile *f, void *opaque, +static void vfio_save_pending(void *opaque, uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 15127d489a..c27ef9b033 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -762,7 +762,7 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void= *opaque) return 0; } =20 -static void dirty_bitmap_save_pending(QEMUFile *f, void *opaque, +static void dirty_bitmap_save_pending(void *opaque, uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, diff --git a/migration/block.c b/migration/block.c index 5da15a62de..47852b8d58 100644 --- a/migration/block.c +++ b/migration/block.c @@ -863,7 +863,7 @@ static int block_save_complete(QEMUFile *f, void *opaqu= e) return 0; } =20 -static void block_save_pending(QEMUFile *f, void *opaque, uint64_t max_siz= e, +static void block_save_pending(void *opaque, uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/migration.c b/migration/migration.c index 52b5d39244..76524cc56e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3751,7 +3751,7 @@ static MigIterateState migration_iteration_run(Migrat= ionState *s) uint64_t pending_size, pend_pre, pend_compat, pend_post; bool in_postcopy =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE; =20 - qemu_savevm_state_pending(s->to_dst_file, s->threshold_size, &pend_pre, + qemu_savevm_state_pending(s->threshold_size, &pend_pre, &pend_compat, &pend_post); pending_size =3D pend_pre + pend_compat + pend_post; =20 diff --git a/migration/ram.c b/migration/ram.c index 68a45338e3..389739f162 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3409,7 +3409,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return 0; } =20 -static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, +static void ram_save_pending(void *opaque, uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/savevm.c b/migration/savevm.c index a783789430..5e4bccb966 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1472,7 +1472,7 @@ flush: * the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size, +void qemu_savevm_state_pending(uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) @@ -1493,7 +1493,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t = threshold_size, continue; } } - se->ops->save_live_pending(f, se->opaque, threshold_size, + se->ops->save_live_pending(se->opaque, threshold_size, res_precopy_only, res_compatible, res_postcopy_only); } --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354266; cv=none; d=zohomail.com; s=zohoarc; b=gcExnVEeGMMpvhj/TgPaDwbvN8o20Jy1xJsNjFrl2Wj3H57cIeD/lNXFYc8uXOgJdNd97TD/uaFOfjc6g4sCCnAkSkELwN8c3zKMr0golLDdpcOsEfxz0L+tQnAWyywp1oNLhoiqGOi/fUf2jE+ubRvndKv/K279042Ws/no+ZA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354266; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5Ig+TS2lzwQqX94+KvxoXv/vGzNfT8L40p0vlRV5lRU=; b=cDY38DoFeTWoogiwD6+RrMiMw5WsBx8xQC9F7ltbcuDUWXp7w61C9nNhJEakvvYA5bigxFkSfHxnY4l3An0ZnYHlkQGhrVWfGxl+Lh7vlXw33lz2YTZRKDv8XeoqoJHtHya7fnoDQVOW4C1sFgtUOYz8XlHIQchnUOlCXn9c2y0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354266402260.7021153636164; Thu, 2 Feb 2023 08:11:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8L-0000is-DF; Thu, 02 Feb 2023 11:08:21 -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 1pNc8H-0000Tq-Dr for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8D-0005En-63 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:17 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-3R3lX5TBNeWknGuULoW_-g-1; Thu, 02 Feb 2023 11:07:31 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 375C7100F825; Thu, 2 Feb 2023 16:07:01 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8826753AA; Thu, 2 Feb 2023 16:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5Ig+TS2lzwQqX94+KvxoXv/vGzNfT8L40p0vlRV5lRU=; b=NPvvTeIWT3HFVmTry933UbY9HVO1pULOAR5EeC/bkkSQ27S89+03Oq6Dqb4EfgSBDDk25u Xzmbo5ne+zVC3l2ZkICypZUarAY5aYxafaFzDRj0in0D9TGbiWU/RpWTW6at2w4CWpM5vY VmJ/p8IkS1H16Wnb13RCgaQFvwkH/yA= X-MC-Unique: 3R3lX5TBNeWknGuULoW_-g-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org Subject: [PULL 03/26] migration: Split save_live_pending() into state_pending_* Date: Thu, 2 Feb 2023 17:06:17 +0100 Message-Id: <20230202160640.2300-4-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354266865100001 Content-Type: text/plain; charset="utf-8" We split the function into to: - state_pending_estimate: We estimate the remaining state size without stopping the machine. - state pending_exact: We calculate the exact amount of remaining state. The only "device" that implements different functions for _estimate() and _exact() is ram. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- docs/devel/migration.rst | 18 ++++++++------- docs/devel/vfio-migration.rst | 4 ++-- include/migration/register.h | 19 +++++++++------ migration/savevm.h | 12 ++++++---- hw/s390x/s390-stattrib.c | 11 +++++---- hw/vfio/migration.c | 21 +++++++++-------- migration/block-dirty-bitmap.c | 15 ++++++------ migration/block.c | 13 ++++++----- migration/migration.c | 20 +++++++++++----- migration/ram.c | 35 ++++++++++++++++++++-------- migration/savevm.c | 42 +++++++++++++++++++++++++++------- hw/vfio/trace-events | 2 +- migration/trace-events | 7 +++--- 13 files changed, 143 insertions(+), 76 deletions(-) diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst index 3e9656d8e0..6f65c23b47 100644 --- a/docs/devel/migration.rst +++ b/docs/devel/migration.rst @@ -482,15 +482,17 @@ An iterative device must provide: - A ``load_setup`` function that initialises the data structures on the destination. =20 - - A ``save_live_pending`` function that is called repeatedly and must - indicate how much more data the iterative data must save. The core - migration code will use this to determine when to pause the CPUs - and complete the migration. + - A ``state_pending_exact`` function that indicates how much more + data we must save. The core migration code will use this to + determine when to pause the CPUs and complete the migration. =20 - - A ``save_live_iterate`` function (called after ``save_live_pending`` - when there is significant data still to be sent). It should send - a chunk of data until the point that stream bandwidth limits tell it - to stop. Each call generates one section. + - A ``state_pending_estimate`` function that indicates how much more + data we must save. When the estimated amount is smaller than the + threshold, we call ``state_pending_exact``. + + - A ``save_live_iterate`` function should send a chunk of data until + the point that stream bandwidth limits tell it to stop. Each call + generates one section. =20 - A ``save_live_complete_precopy`` function that must transmit the last section for the device containing any remaining data. diff --git a/docs/devel/vfio-migration.rst b/docs/devel/vfio-migration.rst index 9ff6163c88..673057c90d 100644 --- a/docs/devel/vfio-migration.rst +++ b/docs/devel/vfio-migration.rst @@ -28,7 +28,7 @@ VFIO implements the device hooks for the iterative approa= ch as follows: * A ``load_setup`` function that sets up the migration region on the destination and sets _RESUMING flag in the VFIO device state. =20 -* A ``save_live_pending`` function that reads pending_bytes from the vendor +* A ``state_pending_exact`` function that reads pending_bytes from the ven= dor driver, which indicates the amount of data that the vendor driver has ye= t to save for the VFIO device. =20 @@ -114,7 +114,7 @@ Live migration save path (RUNNING, _SETUP, _RUNNING|_SAVING) | (RUNNING, _ACTIVE, _RUNNING|_SAVING) - If device is active, get pending_bytes by .save_live_pending() + If device is active, get pending_bytes by .state_pending_exac= t() If total pending_bytes >=3D threshold_size, call .save_live_iter= ate() Data of VFIO device for pre-copy phase is copied Iterate till total pending bytes converge and are less than thresh= old diff --git a/include/migration/register.h b/include/migration/register.h index 6ca71367af..15cf32994d 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -46,11 +46,6 @@ typedef struct SaveVMHandlers { =20 /* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f, void *opaque); - void (*save_live_pending)(void *opaque, - uint64_t threshold_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only); /* Note for save_live_pending: * - res_precopy_only is for data which must be migrated in precopy ph= ase * or in stopped state, in other words - before target vm start @@ -61,8 +56,18 @@ typedef struct SaveVMHandlers { * Sum of res_postcopy_only, res_compatible and res_postcopy_only is t= he * whole amount of pending data. */ - - + /* This estimates the remaining data to transfer */ + void (*state_pending_estimate)(void *opaque, + uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only); + /* This calculate the exact remaining data to transfer */ + void (*state_pending_exact)(void *opaque, + uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only); LoadStateHandler *load_state; int (*load_setup)(QEMUFile *f, void *opaque); int (*load_cleanup)(void *opaque); diff --git a/migration/savevm.h b/migration/savevm.h index 524cf12f25..5d2cff4411 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -40,10 +40,14 @@ void qemu_savevm_state_cleanup(void); void qemu_savevm_state_complete_postcopy(QEMUFile *f); int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, bool inactivate_disks); -void qemu_savevm_state_pending(uint64_t max_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only); +void qemu_savevm_state_pending_exact(uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only); +void qemu_savevm_state_pending_estimate(uint64_t thershold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only); void qemu_savevm_send_ping(QEMUFile *f, uint32_t value); void qemu_savevm_send_open_return_path(QEMUFile *f); int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len); diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index a553a1e850..8f573ebb10 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -182,10 +182,10 @@ static int cmma_save_setup(QEMUFile *f, void *opaque) return 0; } =20 -static void cmma_save_pending(void *opaque, uint64_t max_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +static void cmma_state_pending(void *opaque, uint64_t max_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { S390StAttribState *sas =3D S390_STATTRIB(opaque); S390StAttribClass *sac =3D S390_STATTRIB_GET_CLASS(sas); @@ -371,7 +371,8 @@ static SaveVMHandlers savevm_s390_stattrib_handlers =3D= { .save_setup =3D cmma_save_setup, .save_live_iterate =3D cmma_save_iterate, .save_live_complete_precopy =3D cmma_save_complete, - .save_live_pending =3D cmma_save_pending, + .state_pending_exact =3D cmma_state_pending, + .state_pending_estimate =3D cmma_state_pending, .save_cleanup =3D cmma_save_cleanup, .load_state =3D cmma_load, .is_active =3D cmma_active, diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index b2125c7607..c49ca466d4 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -456,11 +456,11 @@ static void vfio_save_cleanup(void *opaque) trace_vfio_save_cleanup(vbasedev->name); } =20 -static void vfio_save_pending(void *opaque, - uint64_t threshold_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +static void vfio_state_pending(void *opaque, + uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; @@ -473,7 +473,7 @@ static void vfio_save_pending(void *opaque, =20 *res_precopy_only +=3D migration->pending_bytes; =20 - trace_vfio_save_pending(vbasedev->name, *res_precopy_only, + trace_vfio_state_pending(vbasedev->name, *res_precopy_only, *res_postcopy_only, *res_compatible); } =20 @@ -515,9 +515,9 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) } =20 /* - * Reset pending_bytes as .save_live_pending is not called during save= vm or - * snapshot case, in such case vfio_update_pending() at the start of t= his - * function updates pending_bytes. + * Reset pending_bytes as state_pending* are not called during + * savevm or snapshot case, in such case vfio_update_pending() at + * the start of this function updates pending_bytes. */ migration->pending_bytes =3D 0; trace_vfio_save_iterate(vbasedev->name, data_size); @@ -685,7 +685,8 @@ static int vfio_load_state(QEMUFile *f, void *opaque, i= nt version_id) static SaveVMHandlers savevm_vfio_handlers =3D { .save_setup =3D vfio_save_setup, .save_cleanup =3D vfio_save_cleanup, - .save_live_pending =3D vfio_save_pending, + .state_pending_exact =3D vfio_state_pending, + .state_pending_estimate =3D vfio_state_pending, .save_live_iterate =3D vfio_save_iterate, .save_live_complete_precopy =3D vfio_save_complete_precopy, .save_state =3D vfio_save_state, diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index c27ef9b033..6fac9fb34f 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -762,11 +762,11 @@ static int dirty_bitmap_save_complete(QEMUFile *f, vo= id *opaque) return 0; } =20 -static void dirty_bitmap_save_pending(void *opaque, - uint64_t max_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +static void dirty_bitmap_state_pending(void *opaque, + uint64_t max_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { DBMSaveState *s =3D &((DBMState *)opaque)->save; SaveBitmapState *dbms; @@ -784,7 +784,7 @@ static void dirty_bitmap_save_pending(void *opaque, =20 qemu_mutex_unlock_iothread(); =20 - trace_dirty_bitmap_save_pending(pending, max_size); + trace_dirty_bitmap_state_pending(pending); =20 *res_postcopy_only +=3D pending; } @@ -1253,7 +1253,8 @@ static SaveVMHandlers savevm_dirty_bitmap_handlers = =3D { .save_live_complete_postcopy =3D dirty_bitmap_save_complete, .save_live_complete_precopy =3D dirty_bitmap_save_complete, .has_postcopy =3D dirty_bitmap_has_postcopy, - .save_live_pending =3D dirty_bitmap_save_pending, + .state_pending_exact =3D dirty_bitmap_state_pending, + .state_pending_estimate =3D dirty_bitmap_state_pending, .save_live_iterate =3D dirty_bitmap_save_iterate, .is_active_iterate =3D dirty_bitmap_is_active_iterate, .load_state =3D dirty_bitmap_load, diff --git a/migration/block.c b/migration/block.c index 47852b8d58..544e74e9c5 100644 --- a/migration/block.c +++ b/migration/block.c @@ -863,10 +863,10 @@ static int block_save_complete(QEMUFile *f, void *opa= que) return 0; } =20 -static void block_save_pending(void *opaque, uint64_t max_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +static void block_state_pending(void *opaque, uint64_t max_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { /* Estimate pending number of bytes to send */ uint64_t pending; @@ -885,7 +885,7 @@ static void block_save_pending(void *opaque, uint64_t m= ax_size, pending =3D BLK_MIG_BLOCK_SIZE; } =20 - trace_migration_block_save_pending(pending); + trace_migration_block_state_pending(pending); /* We don't do postcopy */ *res_precopy_only +=3D pending; } @@ -1020,7 +1020,8 @@ static SaveVMHandlers savevm_block_handlers =3D { .save_setup =3D block_save_setup, .save_live_iterate =3D block_save_iterate, .save_live_complete_precopy =3D block_save_complete, - .save_live_pending =3D block_save_pending, + .state_pending_exact =3D block_state_pending, + .state_pending_estimate =3D block_state_pending, .load_state =3D block_load, .save_cleanup =3D block_migration_cleanup, .is_active =3D block_is_active, diff --git a/migration/migration.c b/migration/migration.c index 76524cc56e..e7b4b94348 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3748,15 +3748,23 @@ typedef enum { */ static MigIterateState migration_iteration_run(MigrationState *s) { - uint64_t pending_size, pend_pre, pend_compat, pend_post; + uint64_t pend_pre, pend_compat, pend_post; bool in_postcopy =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE; =20 - qemu_savevm_state_pending(s->threshold_size, &pend_pre, - &pend_compat, &pend_post); - pending_size =3D pend_pre + pend_compat + pend_post; + qemu_savevm_state_pending_estimate(s->threshold_size, &pend_pre, + &pend_compat, &pend_post); + uint64_t pending_size =3D pend_pre + pend_compat + pend_post; =20 - trace_migrate_pending(pending_size, s->threshold_size, - pend_pre, pend_compat, pend_post); + trace_migrate_pending_estimate(pending_size, s->threshold_size, + pend_pre, pend_compat, pend_post); + + if (pend_pre + pend_compat <=3D s->threshold_size) { + qemu_savevm_state_pending_exact(s->threshold_size, &pend_pre, + &pend_compat, &pend_post); + pending_size =3D pend_pre + pend_compat + pend_post; + trace_migrate_pending_exact(pending_size, s->threshold_size, + pend_pre, pend_compat, pend_post); + } =20 if (pending_size && pending_size >=3D s->threshold_size) { /* Still a significant amount to transfer */ diff --git a/migration/ram.c b/migration/ram.c index 389739f162..56ff9cd29d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3409,19 +3409,35 @@ static int ram_save_complete(QEMUFile *f, void *opa= que) return 0; } =20 -static void ram_save_pending(void *opaque, uint64_t max_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +static void ram_state_pending_estimate(void *opaque, uint64_t max_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { RAMState **temp =3D opaque; RAMState *rs =3D *temp; - uint64_t remaining_size; =20 - remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SIZE; + uint64_t remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SI= ZE; =20 - if (!migration_in_postcopy() && - remaining_size < max_size) { + if (migrate_postcopy_ram()) { + /* We can do postcopy, and all the data is postcopiable */ + *res_postcopy_only +=3D remaining_size; + } else { + *res_precopy_only +=3D remaining_size; + } +} + +static void ram_state_pending_exact(void *opaque, uint64_t max_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) +{ + RAMState **temp =3D opaque; + RAMState *rs =3D *temp; + + uint64_t remaining_size =3D rs->migration_dirty_pages * TARGET_PAGE_SI= ZE; + + if (!migration_in_postcopy()) { qemu_mutex_lock_iothread(); WITH_RCU_READ_LOCK_GUARD() { migration_bitmap_sync_precopy(rs); @@ -4577,7 +4593,8 @@ static SaveVMHandlers savevm_ram_handlers =3D { .save_live_complete_postcopy =3D ram_save_complete, .save_live_complete_precopy =3D ram_save_complete, .has_postcopy =3D ram_has_postcopy, - .save_live_pending =3D ram_save_pending, + .state_pending_exact =3D ram_state_pending_exact, + .state_pending_estimate =3D ram_state_pending_estimate, .load_state =3D ram_load, .save_cleanup =3D ram_save_cleanup, .load_setup =3D ram_load_setup, diff --git a/migration/savevm.c b/migration/savevm.c index 5e4bccb966..7f9f770c1e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1472,10 +1472,10 @@ flush: * the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending(uint64_t threshold_size, - uint64_t *res_precopy_only, - uint64_t *res_compatible, - uint64_t *res_postcopy_only) +void qemu_savevm_state_pending_estimate(uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) { SaveStateEntry *se; =20 @@ -1485,7 +1485,7 @@ void qemu_savevm_state_pending(uint64_t threshold_siz= e, =20 =20 QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - if (!se->ops || !se->ops->save_live_pending) { + if (!se->ops || !se->ops->state_pending_exact) { continue; } if (se->ops->is_active) { @@ -1493,9 +1493,35 @@ void qemu_savevm_state_pending(uint64_t threshold_si= ze, continue; } } - se->ops->save_live_pending(se->opaque, threshold_size, - res_precopy_only, res_compatible, - res_postcopy_only); + se->ops->state_pending_exact(se->opaque, threshold_size, + res_precopy_only, res_compatible, + res_postcopy_only); + } +} + +void qemu_savevm_state_pending_exact(uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) +{ + SaveStateEntry *se; + + *res_precopy_only =3D 0; + *res_compatible =3D 0; + *res_postcopy_only =3D 0; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (!se->ops || !se->ops->state_pending_estimate) { + continue; + } + if (se->ops->is_active) { + if (!se->ops->is_active(se->opaque)) { + continue; + } + } + se->ops->state_pending_estimate(se->opaque, threshold_size, + res_precopy_only, res_compatible, + res_postcopy_only); } } =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 73dffe9e00..52de1c84f8 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_siz= e, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%= "PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%= "PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, u= int64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compati= ble 0x%"PRIx64 +vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy, = uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compat= ible 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)" diff --git a/migration/trace-events b/migration/trace-events index 57003edcbd..adb680b0e6 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -150,7 +150,8 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=3D%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) = "in %s at 0x%zx len 0x%zx" -migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t compat= , uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre =3D %" PRIu= 64 " compat=3D%" PRIu64 " post=3D%" PRIu64 ")" +migrate_pending_exact(uint64_t size, uint64_t max, uint64_t pre, uint64_t = compat, uint64_t post) "exact pending size %" PRIu64 " max %" PRIu64 " (pre= =3D %" PRIu64 " compat=3D%" PRIu64 " post=3D%" PRIu64 ")" +migrate_pending_estimate(uint64_t size, uint64_t max, uint64_t pre, uint64= _t compat, uint64_t post) "estimate pending size %" PRIu64 " max %" PRIu64 = " (pre =3D %" PRIu64 " compat=3D%" PRIu64 " post=3D%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%= "PRIi64 migration_completion_file_err(void) "" @@ -330,7 +331,7 @@ send_bitmap_bits(uint32_t flags, uint64_t start_sector,= uint32_t nr_sectors, uin dirty_bitmap_save_iterate(int in_postcopy) "in postcopy: %d" dirty_bitmap_save_complete_enter(void) "" dirty_bitmap_save_complete_finish(void) "" -dirty_bitmap_save_pending(uint64_t pending, uint64_t max_size) "pending %"= PRIu64 " max: %" PRIu64 +dirty_bitmap_state_pending(uint64_t pending) "pending %" PRIu64 dirty_bitmap_load_complete(void) "" dirty_bitmap_load_bits_enter(uint64_t first_sector, uint32_t nr_sectors) "= chunk: %" PRIu64 " %" PRIu32 dirty_bitmap_load_bits_zeroes(void) "" @@ -355,7 +356,7 @@ migration_block_save_device_dirty(int64_t sector) "Erro= r reading sector %" PRId6 migration_block_flush_blks(const char *action, int submitted, int read_don= e, int transferred) "%s submitted %d read_done %d transferred %d" migration_block_save(const char *mig_stage, int submitted, int transferred= ) "Enter save live %s submitted %d transferred %d" migration_block_save_complete(void) "Block migration completed" -migration_block_save_pending(uint64_t pending) "Enter save live pending %= " PRIu64 +migration_block_state_pending(uint64_t pending) "Enter save live pending = %" PRIu64 =20 # page_cache.c migration_pagecache_init(int64_t max_num_items) "Setting cache buckets to = %" PRId64 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354096; cv=none; d=zohomail.com; s=zohoarc; b=Jrpd9KVEIrOqZGrju6JEzWpAsOybcFX0Nk+TsXAkpbn6ZBjJM7yA+iBJ6c5u97z9fbMWNuYb9SdK3v/kZ3CEJNbty+LS+vJG2iWFoi2N6i8Zc+Zi+KQ05GQmKnNtwZc4o6m5hK1Y/RlmylqC15VGy4AF37ja37jWU5swUUA24sU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354096; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HN6fE7PnB7WVc8fIdCfznWEmfB0jU4iizxbfGPavGPw=; b=IPmkz+2Y98LjgyciBS8tJNOZIlhX/A20FrfhoW2VOPoMnzcxHKXNFL1txY6P1rTERCBm/WDeQ9axVfWX0I/AQ18dtt5/Ua/uZBbKUWAAnMqrFHHkS/tWp4G7s88NInw8gCfaAgTEPSZ9kPEWBP1zA3VHDj7rtFiUWSVf2/Dzeh4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354096821408.47426729546044; Thu, 2 Feb 2023 08:08:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7h-0007MU-4s; Thu, 02 Feb 2023 11:07: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 1pNc7M-00075E-CC for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7H-00051q-Hp for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:17 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-rfIPKHn0ORi8Mzb97cPVHQ-1; Thu, 02 Feb 2023 11:07:11 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4101218E0920; Thu, 2 Feb 2023 16:07:06 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 835D751E5; Thu, 2 Feb 2023 16:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HN6fE7PnB7WVc8fIdCfznWEmfB0jU4iizxbfGPavGPw=; b=KXJVM1SB6LiDRLCJ2cd310XKwbDN+VVmNVpuqyh3SaMv4OVWbYLXLsKEQwtJOcKD7a7opA 5asoRqDHa2Mh6PYECnr5MwfL3fin/68/Vor+hcR7qjnEpOa6TRq8/piGSVXlszZiw9LMPx +ZLB+L8sffevsvieR6ShQZpApNXCQqw= X-MC-Unique: rfIPKHn0ORi8Mzb97cPVHQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org Subject: [PULL 04/26] migration: Remove unused threshold_size parameter Date: Thu, 2 Feb 2023 17:06:18 +0100 Message-Id: <20230202160640.2300-5-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354099170100007 Content-Type: text/plain; charset="utf-8" Until previous commit, save_live_pending() was used for ram. Now with the split into state_pending_estimate() and state_pending_exact() it is not needed anymore, so remove them. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- include/migration/register.h | 2 -- migration/savevm.h | 6 ++---- hw/s390x/s390-stattrib.c | 2 +- hw/vfio/migration.c | 1 - migration/block-dirty-bitmap.c | 1 - migration/block.c | 2 +- migration/migration.c | 10 ++++------ migration/ram.c | 4 ++-- migration/savevm.c | 11 ++++------- migration/trace-events | 4 ++-- 10 files changed, 16 insertions(+), 27 deletions(-) diff --git a/include/migration/register.h b/include/migration/register.h index 15cf32994d..b91a0cdbf8 100644 --- a/include/migration/register.h +++ b/include/migration/register.h @@ -58,13 +58,11 @@ typedef struct SaveVMHandlers { */ /* This estimates the remaining data to transfer */ void (*state_pending_estimate)(void *opaque, - uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only); /* This calculate the exact remaining data to transfer */ void (*state_pending_exact)(void *opaque, - uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only); diff --git a/migration/savevm.h b/migration/savevm.h index 5d2cff4411..b1901e68d5 100644 --- a/migration/savevm.h +++ b/migration/savevm.h @@ -40,12 +40,10 @@ void qemu_savevm_state_cleanup(void); void qemu_savevm_state_complete_postcopy(QEMUFile *f); int qemu_savevm_state_complete_precopy(QEMUFile *f, bool iterable_only, bool inactivate_disks); -void qemu_savevm_state_pending_exact(uint64_t threshold_size, - uint64_t *res_precopy_only, +void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only); -void qemu_savevm_state_pending_estimate(uint64_t thershold_size, - uint64_t *res_precopy_only, +void qemu_savevm_state_pending_estimate(uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only); void qemu_savevm_send_ping(QEMUFile *f, uint32_t value); diff --git a/hw/s390x/s390-stattrib.c b/hw/s390x/s390-stattrib.c index 8f573ebb10..3e32002eab 100644 --- a/hw/s390x/s390-stattrib.c +++ b/hw/s390x/s390-stattrib.c @@ -182,7 +182,7 @@ static int cmma_save_setup(QEMUFile *f, void *opaque) return 0; } =20 -static void cmma_state_pending(void *opaque, uint64_t max_size, +static void cmma_state_pending(void *opaque, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index c49ca466d4..b3318f0f20 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -457,7 +457,6 @@ static void vfio_save_cleanup(void *opaque) } =20 static void vfio_state_pending(void *opaque, - uint64_t threshold_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c index 6fac9fb34f..5a621419d3 100644 --- a/migration/block-dirty-bitmap.c +++ b/migration/block-dirty-bitmap.c @@ -763,7 +763,6 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void= *opaque) } =20 static void dirty_bitmap_state_pending(void *opaque, - uint64_t max_size, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/block.c b/migration/block.c index 544e74e9c5..29f69025af 100644 --- a/migration/block.c +++ b/migration/block.c @@ -863,7 +863,7 @@ static int block_save_complete(QEMUFile *f, void *opaqu= e) return 0; } =20 -static void block_state_pending(void *opaque, uint64_t max_size, +static void block_state_pending(void *opaque, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/migration.c b/migration/migration.c index e7b4b94348..594a42f085 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3751,18 +3751,16 @@ static MigIterateState migration_iteration_run(Migr= ationState *s) uint64_t pend_pre, pend_compat, pend_post; bool in_postcopy =3D s->state =3D=3D MIGRATION_STATUS_POSTCOPY_ACTIVE; =20 - qemu_savevm_state_pending_estimate(s->threshold_size, &pend_pre, - &pend_compat, &pend_post); + qemu_savevm_state_pending_estimate(&pend_pre, &pend_compat, &pend_post= ); uint64_t pending_size =3D pend_pre + pend_compat + pend_post; =20 - trace_migrate_pending_estimate(pending_size, s->threshold_size, + trace_migrate_pending_estimate(pending_size, pend_pre, pend_compat, pend_post); =20 if (pend_pre + pend_compat <=3D s->threshold_size) { - qemu_savevm_state_pending_exact(s->threshold_size, &pend_pre, - &pend_compat, &pend_post); + qemu_savevm_state_pending_exact(&pend_pre, &pend_compat, &pend_pos= t); pending_size =3D pend_pre + pend_compat + pend_post; - trace_migrate_pending_exact(pending_size, s->threshold_size, + trace_migrate_pending_exact(pending_size, pend_pre, pend_compat, pend_post); } =20 diff --git a/migration/ram.c b/migration/ram.c index 56ff9cd29d..885d7dbf23 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3409,7 +3409,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return 0; } =20 -static void ram_state_pending_estimate(void *opaque, uint64_t max_size, +static void ram_state_pending_estimate(void *opaque, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) @@ -3427,7 +3427,7 @@ static void ram_state_pending_estimate(void *opaque, = uint64_t max_size, } } =20 -static void ram_state_pending_exact(void *opaque, uint64_t max_size, +static void ram_state_pending_exact(void *opaque, uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) diff --git a/migration/savevm.c b/migration/savevm.c index 7f9f770c1e..e1caa3ea7c 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1472,8 +1472,7 @@ flush: * the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending_estimate(uint64_t threshold_size, - uint64_t *res_precopy_only, +void qemu_savevm_state_pending_estimate(uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) { @@ -1483,7 +1482,6 @@ void qemu_savevm_state_pending_estimate(uint64_t thre= shold_size, *res_compatible =3D 0; *res_postcopy_only =3D 0; =20 - QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (!se->ops || !se->ops->state_pending_exact) { continue; @@ -1493,14 +1491,13 @@ void qemu_savevm_state_pending_estimate(uint64_t th= reshold_size, continue; } } - se->ops->state_pending_exact(se->opaque, threshold_size, + se->ops->state_pending_exact(se->opaque, res_precopy_only, res_compatible, res_postcopy_only); } } =20 -void qemu_savevm_state_pending_exact(uint64_t threshold_size, - uint64_t *res_precopy_only, +void qemu_savevm_state_pending_exact(uint64_t *res_precopy_only, uint64_t *res_compatible, uint64_t *res_postcopy_only) { @@ -1519,7 +1516,7 @@ void qemu_savevm_state_pending_exact(uint64_t thresho= ld_size, continue; } } - se->ops->state_pending_estimate(se->opaque, threshold_size, + se->ops->state_pending_estimate(se->opaque, res_precopy_only, res_compatible, res_postcopy_only); } diff --git a/migration/trace-events b/migration/trace-events index adb680b0e6..67b65a70ff 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -150,8 +150,8 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=3D%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) = "in %s at 0x%zx len 0x%zx" -migrate_pending_exact(uint64_t size, uint64_t max, uint64_t pre, uint64_t = compat, uint64_t post) "exact pending size %" PRIu64 " max %" PRIu64 " (pre= =3D %" PRIu64 " compat=3D%" PRIu64 " post=3D%" PRIu64 ")" -migrate_pending_estimate(uint64_t size, uint64_t max, uint64_t pre, uint64= _t compat, uint64_t post) "estimate pending size %" PRIu64 " max %" PRIu64 = " (pre =3D %" PRIu64 " compat=3D%" PRIu64 " post=3D%" PRIu64 ")" +migrate_pending_exact(uint64_t size, uint64_t pre, uint64_t compat, uint64= _t post) "exact pending size %" PRIu64 " (pre =3D %" PRIu64 " compat=3D%" P= RIu64 " post=3D%" PRIu64 ")" +migrate_pending_estimate(uint64_t size, uint64_t pre, uint64_t compat, uin= t64_t post) "estimate pending size %" PRIu64 " (pre =3D %" PRIu64 " compat= =3D%" PRIu64 " post=3D%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%= "PRIi64 migration_completion_file_err(void) "" --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354154; cv=none; d=zohomail.com; s=zohoarc; b=CzaFw/ZoWdS0rw+QH9V51bg4ecg4NjgWdbMQ0wuZ345TEBj1ZxXDPQo1DACOVuj+S23aSo5CDaM0YqmoQx71CIGXZN933ZARGpoXuhSimouww5PB7lvzNyxCV24InBf/9zTfl2AVZ7sAai//2PFH9KqEEDwHo18+t+nMNn7I6ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Kv/9BZKpyVKHs27QEYgoVRqWwmAOZI8qYXYctuD3+Zo=; b=acMTliRjc6uYDpSgOjVfE6vIoE9cSDYbvtiz/3q2hP87IX8CyFgnIapll8ktNBeOUyZS5BoYzsVbmnJ3zK8HGGUpIQDveV/j0LEQzSile+iCNrzSkuontj2sRIvGKCkdoqWMDGzbWVY3BVwoz1EKCPXfFVh9rCybJo7h05qDNg4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354154454782.6203162067395; Thu, 2 Feb 2023 08:09:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7i-0007Qf-7t; Thu, 02 Feb 2023 11:07:42 -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 1pNc7Q-00078T-A1 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7O-00052Q-Nh for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:24 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-575-S9gu23IYOpqYLcytsqi6-Q-1; Thu, 02 Feb 2023 11:07:18 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 003AA101A521; Thu, 2 Feb 2023 16:07:11 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 854B351E5; Thu, 2 Feb 2023 16:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kv/9BZKpyVKHs27QEYgoVRqWwmAOZI8qYXYctuD3+Zo=; b=Y10shhDFb/7+CkOTeVDItCterpay+7mrd3nihR2ijvdNAhEqNw9FaY1xjQaJQNJ5yHSzCo 2xcHr3pL3oH7q95y0R/JwXoeLJJhHU/2jVt/lqU/KJUu7yFeSL7sr4fa/GNR64EFsoR4zR Rw0cM3k5mztvzhATBfwiuvd3UcyOk9w= X-MC-Unique: S9gu23IYOpqYLcytsqi6-Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org Subject: [PULL 05/26] migration: simplify migration_iteration_run() Date: Thu, 2 Feb 2023 17:06:19 +0100 Message-Id: <20230202160640.2300-6-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354155533100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/migration.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 594a42f085..cb9aee76c0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3764,23 +3764,23 @@ static MigIterateState migration_iteration_run(Migr= ationState *s) pend_pre, pend_compat, pend_post); } =20 - if (pending_size && pending_size >=3D s->threshold_size) { - /* Still a significant amount to transfer */ - if (!in_postcopy && pend_pre <=3D s->threshold_size && - qatomic_read(&s->start_postcopy)) { - if (postcopy_start(s)) { - error_report("%s: postcopy failed to start", __func__); - } - return MIG_ITERATE_SKIP; - } - /* Just another iteration step */ - qemu_savevm_state_iterate(s->to_dst_file, in_postcopy); - } else { + if (!pending_size || pending_size < s->threshold_size) { trace_migration_thread_low_pending(pending_size); migration_completion(s); return MIG_ITERATE_BREAK; } =20 + /* Still a significant amount to transfer */ + if (!in_postcopy && pend_pre <=3D s->threshold_size && + qatomic_read(&s->start_postcopy)) { + if (postcopy_start(s)) { + error_report("%s: postcopy failed to start", __func__); + } + return MIG_ITERATE_SKIP; + } + + /* Just another iteration step */ + qemu_savevm_state_iterate(s->to_dst_file, in_postcopy); return MIG_ITERATE_RESUME; } =20 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354171; cv=none; d=zohomail.com; s=zohoarc; b=bRx86US7i0dq0vvnu9MoXHgSXFdnBtMRzvhHCJ3cG2EX5hbgzJdWP94KUYZ7FXK0pkeEND3Ur53uj9PgP9GqO1wXi28uifN+AK0Vm0IAhZBC1wCird495EehalETeI7GGyE06MfBkhkgpL+WsHk8kxjz9BwO/wF8sGVT52bDkFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354171; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B6xgzsWlUhmuOPM7TIr+7bMZ5VQ/A7gez5YeTOVRjsI=; b=GXrP8CJJJH4n/CbDKgFBi/UTFBC4MoSa7lRstp80hUlKpImkElfRtjd/cIlfXwRwqp+v/57OIyY4Rx7nDNikTSQjyal19TPRV9/+idC5GeUiSCrBGD1b7a8owV/OlmtGUN7glmxUrJLw59ayKigOsnRJfsPTD9KQqgxgPsFAtOk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167535417118743.75483989369218; Thu, 2 Feb 2023 08:09:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8L-0000nn-Rf; Thu, 02 Feb 2023 11:08:21 -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 1pNc8G-0000Ti-HN for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8D-0005Ej-GP for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:16 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-ob9HKgVtMmq5LDho8FBvJA-1; Thu, 02 Feb 2023 11:07:32 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3D9743847987; Thu, 2 Feb 2023 16:07:16 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 457C951E5; Thu, 2 Feb 2023 16:07:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B6xgzsWlUhmuOPM7TIr+7bMZ5VQ/A7gez5YeTOVRjsI=; b=I9mImTkM9ZgByTvvesYsdLEmroyypAgygdY+7sLqlKdVCBoV4EOetOJyhz6XDF9yQJJbOk 0SFKG8reLp/6xbB6cTlBF/C3pFOqGgLW4wQCk6EGDf7/RjIJCTyhJ+zP/7V2NRFM8ZlYIP 6dpc9x0LJCaSQlOcsObrMNGEqTgeXCM= X-MC-Unique: ob9HKgVtMmq5LDho8FBvJA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 06/26] util/userfaultfd: Add uffd_open() Date: Thu, 2 Feb 2023 17:06:20 +0100 Message-Id: <20230202160640.2300-7-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354171736100001 From: Peter Xu Add a helper to create the uffd handle. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Peter Xu Signed-off-by: Juan Quintela --- include/qemu/userfaultfd.h | 8 ++++++++ migration/postcopy-ram.c | 11 +++++------ tests/qtest/migration-test.c | 3 ++- util/userfaultfd.c | 13 +++++++++++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/qemu/userfaultfd.h b/include/qemu/userfaultfd.h index 6b74f92792..2101115f70 100644 --- a/include/qemu/userfaultfd.h +++ b/include/qemu/userfaultfd.h @@ -17,6 +17,14 @@ #include "exec/hwaddr.h" #include =20 +/** + * uffd_open(): Open an userfaultfd handle for current context. + * + * @flags: The flags we want to pass in when creating the handle. + * + * Returns: the uffd handle if >=3D0, or <0 if error happens. + */ +int uffd_open(int flags); int uffd_query_features(uint64_t *features); int uffd_create_fd(uint64_t features, bool non_blocking); void uffd_close_fd(int uffd_fd); diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index b9a37ef255..0c55df0e52 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -37,6 +37,7 @@ #include "qemu-file.h" #include "yank_functions.h" #include "tls.h" +#include "qemu/userfaultfd.h" =20 /* Arbitrary limit on size of each discard command, * keeps them around ~200 bytes @@ -226,11 +227,9 @@ static bool receive_ufd_features(uint64_t *features) int ufd; bool ret =3D true; =20 - /* if we are here __NR_userfaultfd should exists */ - ufd =3D syscall(__NR_userfaultfd, O_CLOEXEC); + ufd =3D uffd_open(O_CLOEXEC); if (ufd =3D=3D -1) { - error_report("%s: syscall __NR_userfaultfd failed: %s", __func__, - strerror(errno)); + error_report("%s: uffd_open() failed: %s", __func__, strerror(errn= o)); return false; } =20 @@ -375,7 +374,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingSt= ate *mis) goto out; } =20 - ufd =3D syscall(__NR_userfaultfd, O_CLOEXEC); + ufd =3D uffd_open(O_CLOEXEC); if (ufd =3D=3D -1) { error_report("%s: userfaultfd not available: %s", __func__, strerror(errno)); @@ -1160,7 +1159,7 @@ static int postcopy_temp_pages_setup(MigrationIncomin= gState *mis) int postcopy_ram_incoming_setup(MigrationIncomingState *mis) { /* Open the fd for the kernel to give us userfaults */ - mis->userfault_fd =3D syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK= ); + mis->userfault_fd =3D uffd_open(O_CLOEXEC | O_NONBLOCK); if (mis->userfault_fd =3D=3D -1) { error_report("%s: Failed to open userfault fd: %s", __func__, strerror(errno)); diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 1dd32c9506..7a5d1922dd 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -62,13 +62,14 @@ static bool uffd_feature_thread_id; #include #include #include +#include "qemu/userfaultfd.h" =20 static bool ufd_version_check(void) { struct uffdio_api api_struct; uint64_t ioctl_mask; =20 - int ufd =3D syscall(__NR_userfaultfd, O_CLOEXEC); + int ufd =3D uffd_open(O_CLOEXEC); =20 if (ufd =3D=3D -1) { g_test_message("Skipping test: userfaultfd not available"); diff --git a/util/userfaultfd.c b/util/userfaultfd.c index f1cd6af2b1..4953b3137d 100644 --- a/util/userfaultfd.c +++ b/util/userfaultfd.c @@ -19,6 +19,15 @@ #include #include =20 +int uffd_open(int flags) +{ +#if defined(__NR_userfaultfd) + return syscall(__NR_userfaultfd, flags); +#else + return -EINVAL; +#endif +} + /** * uffd_query_features: query UFFD features * @@ -32,7 +41,7 @@ int uffd_query_features(uint64_t *features) struct uffdio_api api_struct =3D { 0 }; int ret =3D -1; =20 - uffd_fd =3D syscall(__NR_userfaultfd, O_CLOEXEC); + uffd_fd =3D uffd_open(O_CLOEXEC); if (uffd_fd < 0) { trace_uffd_query_features_nosys(errno); return -1; @@ -69,7 +78,7 @@ int uffd_create_fd(uint64_t features, bool non_blocking) uint64_t ioctl_mask =3D BIT(_UFFDIO_REGISTER) | BIT(_UFFDIO_UNREGISTER= ); =20 flags =3D O_CLOEXEC | (non_blocking ? O_NONBLOCK : 0); - uffd_fd =3D syscall(__NR_userfaultfd, flags); + uffd_fd =3D uffd_open(flags); if (uffd_fd < 0) { trace_uffd_create_fd_nosys(errno); return -1; --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354172; cv=none; d=zohomail.com; s=zohoarc; b=PdsNszRChKP57rU3eUwV66YBcYp3zPgzYC6qlEeqqrTeVkke/7Jpi5QL3wfaTrZ5FTpFfaz/eOHWES5cjJxMf46C82u9pnKhFdyVF2TxwE929NInn4mDJwwrfnwaDTZiPtqWpLvAZA/IKu2ws1LyV9IIU27ahuhbRveteC54Dvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354172; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ypsPnyWgNLqIOy/pWtoUGHZ1xhiN89F5ncT+BrUMGVs=; b=ZI8ls+GO2Q4j1H053D2BWTa8yAiSCEsZjJ3HfPo8ucL9OhwTFNV6ruXn1UUjKXpakQlIRCKix7ReAM9AUmyxzLObN+b0i9MEUVlnUBHjQegX14RCaBx1gpcXWsnEGVXuG49Vka9EH9pdD0crJ/A4HjuofmOkeP109FCqgkYmdpc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354172394649.9138475597346; Thu, 2 Feb 2023 08:09:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7i-0007XG-Lq; Thu, 02 Feb 2023 11:07:42 -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 1pNc7X-0007CO-Hn for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7U-00053O-GP for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:30 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-73pi4__jNBWmbsvIkUV1gQ-1; Thu, 02 Feb 2023 11:07:22 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 473D829AB443; Thu, 2 Feb 2023 16:07:21 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 824B951E5; Thu, 2 Feb 2023 16:07:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ypsPnyWgNLqIOy/pWtoUGHZ1xhiN89F5ncT+BrUMGVs=; b=NKspgDiUeKnPe4IfuNaApKfkj/b4JC/W2pP2CgBcPfy63dtRDGrWV3Ffk42V5RIpahGqHQ /c58jgYV9Vj/SaYff9qqUWx36of+W0O2njllnqsTS/HkaYWkXIpjWj6yHB8jfNJ/Fid8ZT ISuTFz1UNrdoTBF5PycNGIV6qskZRqs= X-MC-Unique: 73pi4__jNBWmbsvIkUV1gQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, qemu-stable@nongnu.org, Peter Xu Subject: [PULL 07/26] migration/ram: Fix populate_read_range() Date: Thu, 2 Feb 2023 17:06:21 +0100 Message-Id: <20230202160640.2300-8-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354173753100004 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Unfortunately, commit f7b9dcfbcf44 broke populate_read_range(): the loop end condition is very wrong, resulting in that function not populating the full range. Lets' fix that. Fixes: f7b9dcfbcf44 ("migration/ram: Factor out populating pages readable i= n ram_block_populate_pages()") Cc: qemu-stable@nongnu.org Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/ram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 885d7dbf23..ba228eead4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1774,13 +1774,15 @@ out: static inline void populate_read_range(RAMBlock *block, ram_addr_t offset, ram_addr_t size) { + const ram_addr_t end =3D offset + size; + /* * We read one byte of each page; this will preallocate page tables if * required and populate the shared zeropage on MAP_PRIVATE anonymous = memory * where no page was populated yet. This might require adaption when * supporting other mappings, like shmem. */ - for (; offset < size; offset +=3D block->page_size) { + for (; offset < end; offset +=3D block->page_size) { char tmp =3D *((char *)block->host + offset); =20 /* Don't optimize the read out */ --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354322; cv=none; d=zohomail.com; s=zohoarc; b=n8tkKjSs7dFCTW+i7G2WGVWdj6FRehykDznzz5V0Nu63jbMNpvSK/xtZDFmLIZu+NoYNmMy5mNv4kG0fUtmSe+2HN1VFRfc/kpED8pmeg7/Rx6+7MJEGPV97bggPI1XQ1oO23RdS3mIdfNhjELHzeOJ+ytbszBBJRansBLOMs30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354322; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=haPCYqw8dBiTHO9WqDCahmHDPX0ls4553+sPmN0fSgI=; b=UC1gyIh5p79LrunfgpQORXIUBdZsC0fR/R3AuhaW8akioquEZN2SFDlycmOk0Sq07srSVk1TFWBhBmp9S2eVET+MeK1/MHnmZJvf2apDKgEpO+Uzk5BYuBZHwS33ZBOa7dVuFOcL0TaSPFovez1ZCotLmGyA7SXsYRqho2b+9Ig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354322419452.66422216886906; Thu, 2 Feb 2023 08:12:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7j-0007cv-QO; Thu, 02 Feb 2023 11:07:44 -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 1pNc7h-0007Mn-4T for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7e-00056C-Vm for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:40 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-zP5yguWtPka1TSWpMK-rYw-1; Thu, 02 Feb 2023 11:07:31 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66592882841; Thu, 2 Feb 2023 16:07:26 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F28C51E5; Thu, 2 Feb 2023 16:07:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354058; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=haPCYqw8dBiTHO9WqDCahmHDPX0ls4553+sPmN0fSgI=; b=a5LqbtN0JoSdzyQI+CDcG5yflL/UJT/s276A5QABeyu+CtkyToacAjdBFzZBClEivhJnqc 4gMX9VDnNEHG/NcptTy9kqDfg/GEuHo3SEhMWjfIwNvw0YSgJIiyxlXtI7+vQL1qLKb+5s cNIePRLMz5vK6knHkW7jbQ9nu3WXmw8= X-MC-Unique: zP5yguWtPka1TSWpMK-rYw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, qemu-stable@nongnu.org, Peter Xu Subject: [PULL 08/26] migration/ram: Fix error handling in ram_write_tracking_start() Date: Thu, 2 Feb 2023 17:06:22 +0100 Message-Id: <20230202160640.2300-9-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354323071100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand If something goes wrong during uffd_change_protection(), we would miss to unregister uffd-wp and not release our reference. Fix it by performing the uffd_change_protection(true) last. Note that a uffd_change_protection(false) on the recovery path without a prior uffd_change_protection(false) is fine. Fixes: 278e2f551a09 ("migration: support UFFD write fault processing in ram= _save_iterate()") Cc: qemu-stable@nongnu.org Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/ram.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index ba228eead4..73e5ca93e5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1896,13 +1896,14 @@ int ram_write_tracking_start(void) block->max_length, UFFDIO_REGISTER_MODE_WP, NULL)) { goto fail; } + block->flags |=3D RAM_UF_WRITEPROTECT; + memory_region_ref(block->mr); + /* Apply UFFD write protection to the block memory range */ if (uffd_change_protection(rs->uffdio_fd, block->host, block->max_length, true, false)) { goto fail; } - block->flags |=3D RAM_UF_WRITEPROTECT; - memory_region_ref(block->mr); =20 trace_ram_write_tracking_ramblock_start(block->idstr, block->page_= size, block->host, block->max_length); --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354110; cv=none; d=zohomail.com; s=zohoarc; b=B1NvQY5qGkJ0edp4dKq1AJ7y3RFPqhmgiWHxBFcPclG36HFk4D5ljrYBcKAraDHxe5LUnL2a+6QQBCOtDCNSR6xhb1Y9ArvsOiZIQYfGIFGv6OjN0zCXIuTiJlOmX/NRUGbr4ke4PrrP4m+u1A6+bllVlHMcD3JMfto4FjFFkN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354110; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qzSBIR6LRz6N4Dl8hXA3eueT1HX6gOU9Tw+HrG3oo/w=; b=SnZx7A+h8brsIkiivsIekgo5ANB7/z5T4W/+CC9MOut4354RJu6A/QExHCCMZoaVpg4Hg1w9RTOyEJZYa6ESrODwI3ukPcrkG8ucaGZH4/82Xg4oSS4daq+ok8dttJE/Ff1U2CgHdCMrYwDHgJUgL0zotqE6neTnlAwiaITco+k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354110190176.55588858095075; Thu, 2 Feb 2023 08:08:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7k-0007fh-Ti; Thu, 02 Feb 2023 11:07:44 -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 1pNc7g-0007Km-H2 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7e-00055y-EC for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:40 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-407-8fT2XfxdNgG5ccuNzhdn1A-1; Thu, 02 Feb 2023 11:07:34 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 50ED418E0923; Thu, 2 Feb 2023 16:07:31 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAB9851FF; Thu, 2 Feb 2023 16:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354057; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qzSBIR6LRz6N4Dl8hXA3eueT1HX6gOU9Tw+HrG3oo/w=; b=NVLiv0vDNv1dKj8JXRBVwNT9EAk6pVoW770KOpmD54whW4yrLrGwR3FbDucOXIOn2R6op9 RkkTJOciCc1h6qvaQXSH1eNhUVVuS36Y+yYuFkDS70xGG2FXPtKtwi1F/nYa/ZPJ+TPvDG qUmB79XbUhequhk3S7BIfmx1zYkzPzg= X-MC-Unique: 8fT2XfxdNgG5ccuNzhdn1A-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 09/26] migration/ram: Don't explicitly unprotect when unregistering uffd-wp Date: Thu, 2 Feb 2023 17:06:23 +0100 Message-Id: <20230202160640.2300-10-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354111175100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand When unregistering uffd-wp, older kernels before commit f369b07c86143 ("mm/uffd:reset write protection when unregister with wp-mode") won't clear the uffd-wp PTE bit. When re-registering uffd-wp, the previous uffd-wp PTE bits would trigger again. With above commit, the kernel will clear the uffd-wp PTE bits when unregistering itself. Consequently, we'll clear the uffd-wp PTE bits now twice -- whereby we don't care about clearing them at all: a new background snapshot will re-register uffd-wp and re-protect all memory either way. So let's skip the manual clearing of uffd-wp. If ever relevant, we could clear conditionally in uffd_unregister_memory() -- we just need a way to figure out more recent kernels. Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/ram.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 73e5ca93e5..efaae07dd8 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1918,12 +1918,6 @@ fail: if ((block->flags & RAM_UF_WRITEPROTECT) =3D=3D 0) { continue; } - /* - * In case some memory block failed to be write-protected - * remove protection and unregister all succeeded RAM blocks - */ - uffd_change_protection(rs->uffdio_fd, block->host, block->max_leng= th, - false, false); uffd_unregister_memory(rs->uffdio_fd, block->host, block->max_leng= th); /* Cleanup flags and remove reference */ block->flags &=3D ~RAM_UF_WRITEPROTECT; @@ -1949,9 +1943,6 @@ void ram_write_tracking_stop(void) if ((block->flags & RAM_UF_WRITEPROTECT) =3D=3D 0) { continue; } - /* Remove protection and unregister all affected RAM blocks */ - uffd_change_protection(rs->uffdio_fd, block->host, block->max_leng= th, - false, false); uffd_unregister_memory(rs->uffdio_fd, block->host, block->max_leng= th); =20 trace_ram_write_tracking_ramblock_stop(block->idstr, block->page_s= ize, --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354154; cv=none; d=zohomail.com; s=zohoarc; b=fqaC5WIar17+udLWN/Bjm2om6C89DDPE8UboFGykrAaVs/zti1Z4TpTXTNz7JRFSCYAPCK5A3KUxZhzaql4TPrqSFtoPBa+tUWO2sJ2YNqQ28LqOqK1oJS1+YRmwnhqpzZu7KQBhXbEu2PWJshft2c++Iv2dzZgjkNUtIbVRDyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354154; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6lIg7aqLoDZba0OtgiOTBlqeFrJWsZnu9N17z0NU7N0=; b=Nl5rZwaEDhIqfKjghoh3qTSa1hTZ83NFNqomTyqyne/MsWm3fLM9bpJDQz99EZXyD92qmaN5eJu+MY/owsTB+lw2INplEJ5FL7e9350XNyykMuo00UdKp1BWvXcj64ePySKp4yLszNU3yFmYHnDP4fy/hsLSvygC3G5LUbntdyw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354154470733.0845421504922; Thu, 2 Feb 2023 08:09:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7l-0007iu-Tt; Thu, 02 Feb 2023 11:07:45 -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 1pNc7j-0007bl-Ez for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7h-00057M-Sl for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:43 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-528-hAFacFWqNEqrPJ9XDlOaeQ-1; Thu, 02 Feb 2023 11:07:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3852C3847992; Thu, 2 Feb 2023 16:07:36 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9682951E5; Thu, 2 Feb 2023 16:07:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354061; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6lIg7aqLoDZba0OtgiOTBlqeFrJWsZnu9N17z0NU7N0=; b=AUn4G583BF9nMoIWbCqVhS6LXGFm30SSTPWMMSvAPjLVTRLRP5tioNMQxFNlL/ZdDpLR+s Iva571eiOrq1bPMh8GuGffa/59gTJosffDhC5Pudd1IYqxoE8mmjXUcEgmQlOW7GzPlsNn EJn/5KUWsMsjOMjHHUB9k1Y8xgBc9Xk= X-MC-Unique: hAFacFWqNEqrPJ9XDlOaeQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 10/26] migration/ram: Rely on used_length for uffd_change_protection() Date: Thu, 2 Feb 2023 17:06:24 +0100 Message-Id: <20230202160640.2300-11-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354155528100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand ram_mig_ram_block_resized() will abort migration (including background snapshots) when resizing a RAMBlock. ram_block_populate_read() will only populate RAM up to used_length, so at least for anonymous memory protecting everything between used_length and max_length won't actually be protected and is just a NOP. So let's only protect everything up to used_length. Note: it still makes sense to register uffd-wp for max_length, such that RAM_UF_WRITEPROTECT is independent of a changing used_length. Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/ram.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index efaae07dd8..a6956c9e7d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1901,7 +1901,7 @@ int ram_write_tracking_start(void) =20 /* Apply UFFD write protection to the block memory range */ if (uffd_change_protection(rs->uffdio_fd, block->host, - block->max_length, true, false)) { + block->used_length, true, false)) { goto fail; } =20 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354460; cv=none; d=zohomail.com; s=zohoarc; b=B/7ZAqAoXhRrwXEk9x9I6lSvXJca2yCDaopTDmljtGn+RW5A6fVlJgR5pSjKo9zeIvBlxX81iQzv/hWQLaqDRB6zzssVy6UJ5lOcCkQPUJ9W2/miwDNUvT6IPRn+anp5VteRL57KkpEBy9G+rAj0+V7X4nW8Z5qq4yLX8MG1D3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354460; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DYITrzVxeANIn4myE/xtt+IWMtwojgiIpFXvIFEzIJQ=; b=ftoT8hLRxASTkTJwn6yeR2iVrO6+pTMoUOySVUIaBvXDAX196zs6YSkrub6B3WeFIjFKSp+2xKtRnQfTlJRi2L2iv7vCNqoG7kWxgjBl6w0KWZEIwu733/+L+coem8KrQUILvm7z+40jbU6/RdqR1vCKBXdeZtscD0nvqLPEV18= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354460018546.7659791927226; Thu, 2 Feb 2023 08:14:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc93-0003fU-3g; Thu, 02 Feb 2023 11:09:05 -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 1pNc91-0003QR-09 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8y-0005SI-Iu for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:02 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-640-_9Tbl78oPsGhyaaFKsYeQA-1; Thu, 02 Feb 2023 11:08:10 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EAFF857AA3; Thu, 2 Feb 2023 16:07:41 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 858B253AA; Thu, 2 Feb 2023 16:07:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354139; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DYITrzVxeANIn4myE/xtt+IWMtwojgiIpFXvIFEzIJQ=; b=hbY9+b8/auUpCCjp4xxWgfnwU6ORYo4njCqTY+BwsowCWeB5euQSRQx2Nc64HETum9H3zT l7UdmwjFV2dQyp+ZNQRdC2fo7gxI3vIDDzrHDrs5QaRo5W1+JN+Xe1ExbleVODB32Ilfbk 2PCzsSIJxtlf4p5ythPZwQhQFHGpMF0= X-MC-Unique: _9Tbl78oPsGhyaaFKsYeQA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 11/26] migration/ram: Optimize ram_write_tracking_start() for RamDiscardManager Date: Thu, 2 Feb 2023 17:06:25 +0100 Message-Id: <20230202160640.2300-12-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354461380100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand ram_block_populate_read() already optimizes for RamDiscardManager. However, ram_write_tracking_start() will still try protecting discarded memory ranges. Let's optimize, because discarded ranges don't map any pages and (1) For anonymous memory, trying to protect using uffd-wp without a mapped page is ignored by the kernel and consequently a NOP. (2) For shared/file-backed memory, we will fill present page tables in the range with PTE markers. However, we will even allocate page tables just to fill them with unnecessary PTE markers and effectively waste memory. So let's exclude these ranges, just like ram_block_populate_read() already does. Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/ram.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index a6956c9e7d..7f6d5efe8d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1865,6 +1865,39 @@ void ram_write_tracking_prepare(void) } } =20 +static inline int uffd_protect_section(MemoryRegionSection *section, + void *opaque) +{ + const hwaddr size =3D int128_get64(section->size); + const hwaddr offset =3D section->offset_within_region; + RAMBlock *rb =3D section->mr->ram_block; + int uffd_fd =3D (uintptr_t)opaque; + + return uffd_change_protection(uffd_fd, rb->host + offset, size, true, + false); +} + +static int ram_block_uffd_protect(RAMBlock *rb, int uffd_fd) +{ + assert(rb->flags & RAM_UF_WRITEPROTECT); + + /* See ram_block_populate_read() */ + if (rb->mr && memory_region_has_ram_discard_manager(rb->mr)) { + RamDiscardManager *rdm =3D memory_region_get_ram_discard_manager(r= b->mr); + MemoryRegionSection section =3D { + .mr =3D rb->mr, + .offset_within_region =3D 0, + .size =3D rb->mr->size, + }; + + return ram_discard_manager_replay_populated(rdm, §ion, + uffd_protect_section, + (void *)(uintptr_t)uff= d_fd); + } + return uffd_change_protection(uffd_fd, rb->host, + rb->used_length, true, false); +} + /* * ram_write_tracking_start: start UFFD-WP memory tracking * @@ -1900,8 +1933,7 @@ int ram_write_tracking_start(void) memory_region_ref(block->mr); =20 /* Apply UFFD write protection to the block memory range */ - if (uffd_change_protection(rs->uffdio_fd, block->host, - block->used_length, true, false)) { + if (ram_block_uffd_protect(block, uffd_fd)) { goto fail; } =20 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354096; cv=none; d=zohomail.com; s=zohoarc; b=Gt2D8ThPUpYCHd1ZJtxrQF7HoPodwcrLKx9+oSdBAgbFiQN2bMAvcrBbCipvaU1Z/oHc3bIsY4xKclJgJJ9o1YyLq/vQSn4O2zjBs1Jx2KaoKsX6Fhiv5ub5UlQhpXDIs1uaxHMetF4FjY+es91SLdxTFmk7LgNizj7wn/tRMiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354096; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3H2e5YeH5/21K34UaegkcQcfDpUz2GgM6q4M95PjxcQ=; b=LH9kYMQppTZnCjibheE2/mFWaTfOvuKBCkpgWxqijSc84rDwcHh/P1r3igbsoZOetzo12oS/MalGqmGFdVYlU3FX8HstwlEBJ4DfusUtL9vfsrt812RX5gDfbCFsE0I/Et4BrUKis8FLnGVCKb4eHbSRrHzgz0dWL7SkFqZ9AJk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354096592187.0775463951627; Thu, 2 Feb 2023 08:08:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc7w-0008MX-U7; Thu, 02 Feb 2023 11:07:56 -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 1pNc7u-0008HT-Ls for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc7s-00059f-BD for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:07:54 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-445-PV_VloGmMz24_vCkcarOsQ-1; Thu, 02 Feb 2023 11:07:47 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66DB58828C0; Thu, 2 Feb 2023 16:07:46 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DBF051E5; Thu, 2 Feb 2023 16:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3H2e5YeH5/21K34UaegkcQcfDpUz2GgM6q4M95PjxcQ=; b=a5rXRL6xvphlMCz5T9fAWANtdqIy9XUVJu6eac5q+lBQWtkXAJ+xYCwa1M5h0t2SoNu720 iBiyOpi3J4QUSJoPCRiip48AqX8vxtAQz9z6V8Ai36W/NLtP0HO/1cYWw1Q8EK5uDXPrlP EjJ0Wkvv/Td4ZRatTc+4jw/odW/Uj7s= X-MC-Unique: PV_VloGmMz24_vCkcarOsQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 12/26] migration/savevm: Move more savevm handling into vmstate_save() Date: Thu, 2 Feb 2023 17:06:26 +0100 Message-Id: <20230202160640.2300-13-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354097469100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's move more code into vmstate_save(), reducing code duplication and preparing for reuse of vmstate_save() in qemu_savevm_state_setup(). We have to move vmstate_save() to make the compiler happy. We'll now also trace from qemu_save_device_state(), triggering the same tracepoints as previously called from qemu_savevm_state_complete_precopy_non_iterable() only. Note that qemu_save_device_state() ignores iterable device state, such as RAM, and consequently doesn't trigger some other trace points (e.g., trace_savevm_state_setup()). Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/savevm.c | 79 ++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index e1caa3ea7c..3e3631652e 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -898,17 +898,6 @@ static void vmstate_save_old_style(QEMUFile *f, SaveSt= ateEntry *se, } } =20 -static int vmstate_save(QEMUFile *f, SaveStateEntry *se, - JSONWriter *vmdesc) -{ - trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); - if (!se->vmsd) { - vmstate_save_old_style(f, se, vmdesc); - return 0; - } - return vmstate_save_state(f, se->vmsd, se->opaque, vmdesc); -} - /* * Write the header for device section (QEMU_VM_SECTION START/END/PART/FUL= L) */ @@ -942,6 +931,43 @@ static void save_section_footer(QEMUFile *f, SaveState= Entry *se) } } =20 +static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdes= c) +{ + int ret; + + if ((!se->ops || !se->ops->save_state) && !se->vmsd) { + return 0; + } + if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) { + trace_savevm_section_skip(se->idstr, se->section_id); + return 0; + } + + trace_savevm_section_start(se->idstr, se->section_id); + save_section_header(f, se, QEMU_VM_SECTION_FULL); + if (vmdesc) { + json_writer_start_object(vmdesc, NULL); + json_writer_str(vmdesc, "name", se->idstr); + json_writer_int64(vmdesc, "instance_id", se->instance_id); + } + + trace_vmstate_save(se->idstr, se->vmsd ? se->vmsd->name : "(old)"); + if (!se->vmsd) { + vmstate_save_old_style(f, se, vmdesc); + } else { + ret =3D vmstate_save_state(f, se->vmsd, se->opaque, vmdesc); + if (ret) { + return ret; + } + } + + trace_savevm_section_end(se->idstr, se->section_id, 0); + save_section_footer(f, se); + if (vmdesc) { + json_writer_end_object(vmdesc); + } + return 0; +} /** * qemu_savevm_command_send: Send a 'QEMU_VM_COMMAND' type element with the * command and associated data. @@ -1375,31 +1401,11 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, json_writer_int64(vmdesc, "page_size", qemu_target_page_size()); json_writer_start_array(vmdesc, "devices"); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { - - if ((!se->ops || !se->ops->save_state) && !se->vmsd) { - continue; - } - if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) { - trace_savevm_section_skip(se->idstr, se->section_id); - continue; - } - - trace_savevm_section_start(se->idstr, se->section_id); - - json_writer_start_object(vmdesc, NULL); - json_writer_str(vmdesc, "name", se->idstr); - json_writer_int64(vmdesc, "instance_id", se->instance_id); - - save_section_header(f, se, QEMU_VM_SECTION_FULL); ret =3D vmstate_save(f, se, vmdesc); if (ret) { qemu_file_set_error(f, ret); return ret; } - trace_savevm_section_end(se->idstr, se->section_id, 0); - save_section_footer(f, se); - - json_writer_end_object(vmdesc); } =20 if (inactivate_disks) { @@ -1618,21 +1624,10 @@ int qemu_save_device_state(QEMUFile *f) if (se->is_ram) { continue; } - if ((!se->ops || !se->ops->save_state) && !se->vmsd) { - continue; - } - if (se->vmsd && !vmstate_save_needed(se->vmsd, se->opaque)) { - continue; - } - - save_section_header(f, se, QEMU_VM_SECTION_FULL); - ret =3D vmstate_save(f, se, NULL); if (ret) { return ret; } - - save_section_footer(f, se); } =20 qemu_put_byte(f, QEMU_VM_EOF); --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354197; cv=none; d=zohomail.com; s=zohoarc; b=jBjUDy+BoG4KwQboqabuVBm5MyoSE974vDv4+gjgtBLZVlCRetYYNbMo0vHqAL5zqom6Wa1MY4N3lO+JKnF6gNzJ1J6hn4Yp3UFxDzuRgvQQ06XbnSAlKrov8++E30e5lcMs3CL9Gyg8VGoUYr2YDZnzl82QDiUrFwYismVNym4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354197; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OLAGoLmZqcKzTwxr0WR3o6KYIS2/7nUjb5oI0hxKkYs=; b=jSGli21y1x5FiY7gk7CxshaNvFeFjXfrSnEYct/C1+5uD+/L9Axk+X6BRNqIEh5rXCwXZVvkBlhIy2oiLdp3vT+BGDh+GN5jNBrOseoCZl/sZMbPxnjrFFgju6qfMdCQamrBZmtD1qZ64thUuTHfyDcUPmbC12E9F7r+7S69yqA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354197180426.2117494285303; Thu, 2 Feb 2023 08:09:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc88-00004z-Ff; Thu, 02 Feb 2023 11:08:08 -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 1pNc84-0008UA-K3 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc82-0005Cd-7A for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-543-iZMMFGEKODmlR5hY1Q-kuQ-1; Thu, 02 Feb 2023 11:07:52 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A446857A99; Thu, 2 Feb 2023 16:07:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B040451E5; Thu, 2 Feb 2023 16:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OLAGoLmZqcKzTwxr0WR3o6KYIS2/7nUjb5oI0hxKkYs=; b=MroxaQKxjgFcYvPdUKgyCe+4IOGfa1WxmOCGm2zEC812fUpjg6Yj7EnV5Kf8InvZaSko7N 2hukI/NKTSho32BQJsXcQkPZ6/X2xgGsybtR6ypq1Nzn4ZLyXX7fkXrwRc+9yN04s0aoEv uxM04fVBzD18cp/TMxQXOXK9dl61Y8g= X-MC-Unique: iZMMFGEKODmlR5hY1Q-kuQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 13/26] migration/savevm: Prepare vmdesc json writer in qemu_savevm_state_setup() Date: Thu, 2 Feb 2023 17:06:27 +0100 Message-Id: <20230202160640.2300-14-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354197932100001 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand ... and store it in the migration state. This is a preparation for storing selected vmds's already in qemu_savevm_state_setup(). Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- migration/migration.h | 4 ++++ migration/migration.c | 2 ++ migration/savevm.c | 18 ++++++++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index ae4ffd3454..66511ce532 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -17,6 +17,7 @@ #include "exec/cpu-common.h" #include "hw/qdev-core.h" #include "qapi/qapi-types-migration.h" +#include "qapi/qmp/json-writer.h" #include "qemu/thread.h" #include "qemu/coroutine_int.h" #include "io/channel.h" @@ -366,6 +367,9 @@ struct MigrationState { * This save hostname when out-going migration starts */ char *hostname; + + /* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. = */ + JSONWriter *vmdesc; }; =20 void migrate_set_state(int *state, int old_state, int new_state); diff --git a/migration/migration.c b/migration/migration.c index cb9aee76c0..3344c95d26 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1903,6 +1903,8 @@ static void migrate_fd_cleanup(MigrationState *s) =20 g_free(s->hostname); s->hostname =3D NULL; + json_writer_free(s->vmdesc); + s->vmdesc =3D NULL; =20 qemu_savevm_state_cleanup(); =20 diff --git a/migration/savevm.c b/migration/savevm.c index 3e3631652e..28f88b5521 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -42,7 +42,6 @@ #include "postcopy-ram.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qapi/qmp/json-writer.h" #include "qapi/clone-visitor.h" #include "qapi/qapi-builtin-visit.h" #include "qapi/qmp/qerror.h" @@ -1190,10 +1189,16 @@ bool qemu_savevm_state_guest_unplug_pending(void) =20 void qemu_savevm_state_setup(QEMUFile *f) { + MigrationState *ms =3D migrate_get_current(); SaveStateEntry *se; Error *local_err =3D NULL; int ret; =20 + ms->vmdesc =3D json_writer_new(false); + json_writer_start_object(ms->vmdesc, NULL); + json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size()); + json_writer_start_array(ms->vmdesc, "devices"); + trace_savevm_state_setup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { if (!se->ops || !se->ops->save_setup) { @@ -1391,15 +1396,12 @@ int qemu_savevm_state_complete_precopy_non_iterable= (QEMUFile *f, bool in_postcopy, bool inactivate_disks) { - g_autoptr(JSONWriter) vmdesc =3D NULL; + MigrationState *ms =3D migrate_get_current(); + JSONWriter *vmdesc =3D ms->vmdesc; int vmdesc_len; SaveStateEntry *se; int ret; =20 - vmdesc =3D json_writer_new(false); - json_writer_start_object(vmdesc, NULL); - json_writer_int64(vmdesc, "page_size", qemu_target_page_size()); - json_writer_start_array(vmdesc, "devices"); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { ret =3D vmstate_save(f, se, vmdesc); if (ret) { @@ -1434,6 +1436,10 @@ int qemu_savevm_state_complete_precopy_non_iterable(= QEMUFile *f, qemu_put_buffer(f, (uint8_t *)json_writer_get(vmdesc), vmdesc_len); } =20 + /* Free it now to detect any inconsistencies. */ + json_writer_free(vmdesc); + ms->vmdesc =3D NULL; + return 0; } =20 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354166; cv=none; d=zohomail.com; s=zohoarc; b=T1vJrwpmEJbJqgZ4GjcWSsLQspQ4wab8Y0wqH8XzJs8fjv32+Bbk4u9nOUb6/QGs6NHeoqL5JVlgsZRTpMrTi589ojth4VaIk2tpmupu6VAFOP0oymhxkgCJQ3Ia7KjTUx5W4F2mPgFaYUvmxXXjnL0QB4Vxs1agFyUgL0+EYds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354166; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Lw58clu7Y1bzBf2f7fvddUJNRU5/Wbva2ZRRL1vM7CM=; b=VvUbmFLYS/47IerEBMt7x2b+Dm5JrVLt8KiWMfOVm+tnHocfcjj+LoHmX2nuKM/I1Iqg0niwtZg4RWfQnij+J2bN0cKilQ1TO3SzvlbNbP78RjkfhZ9LNJtvFA061gDbXda9nUwi9dJy1H9wDXjX/5sr1ZJdBb7wVmPd9kWQL+4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354166103772.9411766046551; Thu, 2 Feb 2023 08:09:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8C-000089-DO; Thu, 02 Feb 2023 11:08:12 -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 1pNc87-0008WQ-AW for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc85-0005D6-BK for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:06 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-ZP579hpsNQWGFVc9znId1Q-1; Thu, 02 Feb 2023 11:07:59 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46F47801779; Thu, 2 Feb 2023 16:07:56 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5DBA51E5; Thu, 2 Feb 2023 16:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lw58clu7Y1bzBf2f7fvddUJNRU5/Wbva2ZRRL1vM7CM=; b=DR9Bf9SWprXeeFHpOYlAVkAOGMi0fdHZwlG14A7OsAVrA+SiCNQ73615XiahxRefFjGXL8 nMgkxuCWeknNwCg3lclz1SBRA2JTqhSjEHHX7dqZvrdwvfGnjHHn3SQ/NPAYsHAXUCGuRE akWCAelzK1ivGxnsdJqCg8xaBR/molk= X-MC-Unique: ZP579hpsNQWGFVc9znId1Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 14/26] migration/savevm: Allow immutable device state to be migrated early (i.e., before RAM) Date: Thu, 2 Feb 2023 17:06:28 +0100 Message-Id: <20230202160640.2300-15-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354168115100003 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand For virtio-mem, we want to have the plugged/unplugged state of memory blocks available before migrating any actual RAM content, and perform sanity checks before touching anything on the destination. This information is immutable on the migration source while migration is active, We want to use this information for proper preallocation support with migration: currently, we don't preallocate memory on the migration target, and especially with hugetlb, we can easily run out of hugetlb pages during RAM migration and will crash (SIGBUS) instead of catching this gracefully via preallocation. Migrating device state via a VMSD before we start iterating is currently impossible: the only approach that would be possible is avoiding a VMSD and migrating state manually during save_setup(), to be restored during load_state(). Let's allow for migrating device state via a VMSD early, during the setup phase in qemu_savevm_state_setup(). To keep it simple, we indicate applicable VMSD's using an "early_setup" flag. Note that only very selected devices (i.e., ones seriously messing with RAM setup) are supposed to make use of such early state migration. While at it, also use a bool for the "unmigratable" member. Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 16 +++++++++++++++- migration/savevm.c | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index ad24aa1934..64680d824e 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -178,7 +178,21 @@ struct VMStateField { =20 struct VMStateDescription { const char *name; - int unmigratable; + bool unmigratable; + /* + * This VMSD describes something that should be sent during setup phase + * of migration. It plays similar role as save_setup() for explicitly + * registered vmstate entries, so it can be seen as a way to describe + * save_setup() in VMSD structures. + * + * Note that for now, a SaveStateEntry cannot have a VMSD and + * operations (e.g., save_setup()) set at the same time. Consequently, + * save_setup() and a VMSD with early_setup set to true are mutually + * exclusive. For this reason, also early_setup VMSDs are migrated in a + * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in + * a QEMU_VM_SECTION_START section. + */ + bool early_setup; int version_id; int minimum_version_id; MigrationPriority priority; diff --git a/migration/savevm.c b/migration/savevm.c index 28f88b5521..6d985ad4af 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -1201,6 +1201,15 @@ void qemu_savevm_state_setup(QEMUFile *f) =20 trace_savevm_state_setup(); QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->vmsd && se->vmsd->early_setup) { + ret =3D vmstate_save(f, se, ms->vmdesc); + if (ret) { + qemu_file_set_error(f, ret); + break; + } + continue; + } + if (!se->ops || !se->ops->save_setup) { continue; } @@ -1403,6 +1412,11 @@ int qemu_savevm_state_complete_precopy_non_iterable(= QEMUFile *f, int ret; =20 QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { + if (se->vmsd && se->vmsd->early_setup) { + /* Already saved during qemu_savevm_state_setup(). */ + continue; + } + ret =3D vmstate_save(f, se, vmdesc); if (ret) { qemu_file_set_error(f, ret); --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354100; cv=none; d=zohomail.com; s=zohoarc; b=eBjg/D8ZRrfATb6ZKptJstdTmmXmi8jLZUvFMMNzmxUat0unW2LerwghxlbwcuuHZb2ayiZa9Hy520jW3pmEj3F8O1ZxONTBNE2LmNR/cvQLupAE+ztu1//+YrEpzgNQUP+oBwp9AhI9T/zvAtFF5qLtALYXD2XZHaONAxKvqRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354100; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DenhEVPqZWI8U/oaBiFpU68cmZm9r5bjKt8BUGFm1K4=; b=XMb5B6Y8G2ONsHA2iaeXJ36ke9Ep1PvRbrptjTT99GaIo82CsTeF46hnDL3J0m6EXkUFWb91mEjvHePkO4SFQj2kYsW6XOg+PVIfWRMq7LlAeRscPr6+TPK0O7iQx06CDgf0XiBv7AvlwoW686worZ+0uANwY+h+kc5wvt2ApWo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354100296743.2599350194819; Thu, 2 Feb 2023 08:08:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8B-00006e-Mv; Thu, 02 Feb 2023 11:08:11 -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 1pNc88-000056-9n for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc86-0005DV-Kp for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:08 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-25--Pa2L8Q6MhmFbFyysC6DpA-1; Thu, 02 Feb 2023 11:08:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78750384798C; Thu, 2 Feb 2023 16:08:01 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91CF851E5; Thu, 2 Feb 2023 16:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DenhEVPqZWI8U/oaBiFpU68cmZm9r5bjKt8BUGFm1K4=; b=clDn0YiyKoJl8WT6Ec+QoYZu7Gfr8v9sfAsAszXNG5EGGft0lgPXApT/AnXTuC3PzsoVA5 wj4c5H/Qne8wPV9SPryaoD5WhAuI8S54VtquuJuogjmW/WLOiIMWG3BlBgVt+9NENZHEr+ 7k8b/t8OM8Gq/gG3OuB0xgVpwhfQJus= X-MC-Unique: -Pa2L8Q6MhmFbFyysC6DpA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 15/26] migration/vmstate: Introduce VMSTATE_WITH_TMP_TEST() and VMSTATE_BITMAP_TEST() Date: Thu, 2 Feb 2023 17:06:29 +0100 Message-Id: <20230202160640.2300-16-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354101270100011 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand We'll make use of both next in the context of virtio-mem. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 64680d824e..28a3b92aa1 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -719,8 +719,9 @@ extern const VMStateInfo vmstate_info_qlist; * '_state' type * That the pointer is right at the start of _tmp_type. */ -#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) { \ +#define VMSTATE_WITH_TMP_TEST(_state, _test, _tmp_type, _vmsd) { \ .name =3D "tmp", \ + .field_exists =3D (_test), \ .size =3D sizeof(_tmp_type) + \ QEMU_BUILD_BUG_ON_ZERO(offsetof(_tmp_type, parent) != =3D 0) + \ type_check_pointer(_state, \ @@ -729,6 +730,9 @@ extern const VMStateInfo vmstate_info_qlist; .info =3D &vmstate_info_tmp, \ } =20 +#define VMSTATE_WITH_TMP(_state, _tmp_type, _vmsd) \ + VMSTATE_WITH_TMP_TEST(_state, NULL, _tmp_type, _vmsd) + #define VMSTATE_UNUSED_BUFFER(_test, _version, _size) { \ .name =3D "unused", \ .field_exists =3D (_test), \ @@ -752,8 +756,9 @@ extern const VMStateInfo vmstate_info_qlist; /* _field_size should be a int32_t field in the _state struct giving the * size of the bitmap _field in bits. */ -#define VMSTATE_BITMAP(_field, _state, _version, _field_size) { \ +#define VMSTATE_BITMAP_TEST(_field, _state, _test, _version, _field_size) = { \ .name =3D (stringify(_field)), \ + .field_exists =3D (_test), \ .version_id =3D (_version), \ .size_offset =3D vmstate_offset_value(_state, _field_size, int32_t),\ .info =3D &vmstate_info_bitmap, \ @@ -761,6 +766,9 @@ extern const VMStateInfo vmstate_info_qlist; .offset =3D offsetof(_state, _field), \ } =20 +#define VMSTATE_BITMAP(_field, _state, _version, _field_size) \ + VMSTATE_BITMAP_TEST(_field, _state, NULL, _version, _field_size) + /* For migrating a QTAILQ. * Target QTAILQ needs be properly initialized. * _type: type of QTAILQ element --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354187; cv=none; d=zohomail.com; s=zohoarc; b=Rpky6T/kwxMeTw3QvIbyq3V9XlJlyJgOwhZap8YpFVD9OMFN1RajMKzGiumvWyw6KdS9FbYHtRxV3wZfw1Q+hv51GrW/frfuzT7VgZir8uFbx3L7/NF8sWpYUqCEudR9Ign3Yph96/gLtaZaAqG0kC4Sz/T5ArTxTYezVwPBSRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354187; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D7RGZB1gkplzzqiltCGO+3nBvixE/DwWqw/eHzze3N8=; b=j16n4BqlaHCbrxXJR+GwCAsbTXjcSjVetKrxQM3S/xd5BouTvuL+ng1FciOyZFfF91eeLYZb8+HsBayaB2QgtuE8jtQCxbEbJD44Rskqo5tmDyn0pXakh1wtQ2/MrTf8ha8Crl3zdV2etlO+LQ644laC2c4G7ebhE2AYBBUBNHk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354187416290.96018336682937; Thu, 2 Feb 2023 08:09:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8J-0000X9-JF; Thu, 02 Feb 2023 11:08:19 -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 1pNc8E-0000K0-Tb for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8C-0005Eg-S6 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:14 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-97-ug6hwbXTOdKqHzEYLHeuGA-1; Thu, 02 Feb 2023 11:08:09 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ADD693847987; Thu, 2 Feb 2023 16:08:06 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD54551E5; Thu, 2 Feb 2023 16:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D7RGZB1gkplzzqiltCGO+3nBvixE/DwWqw/eHzze3N8=; b=DgC9mwZtfeiVm9kDQyUMyMTdFI5pY933a7em4InmSTyySJsiONdAJ3HfCP/9OAKz+I9qhf me1TE9f3VxIqnr9xp1lRfPtAMTKhB3heSMiEdSZ+yrgrvtuvtl+al7jNFsQ5tJbfEBgBP1 qsHuv6eHW0xwHwWQOiHxYZcCCXswtUE= X-MC-Unique: ug6hwbXTOdKqHzEYLHeuGA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 16/26] migration/ram: Factor out check for advised postcopy Date: Thu, 2 Feb 2023 17:06:30 +0100 Message-Id: <20230202160640.2300-17-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354187773100003 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Let's factor out this check, to be used in virtio-mem context next. While at it, fix a spelling error in a related comment. Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- include/migration/misc.h | 4 +++- migration/migration.c | 7 +++++++ migration/ram.c | 8 +------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/migration/misc.h b/include/migration/misc.h index 465906710d..8b49841016 100644 --- a/include/migration/misc.h +++ b/include/migration/misc.h @@ -67,8 +67,10 @@ bool migration_has_failed(MigrationState *); /* ...and after the device transmission */ bool migration_in_postcopy_after_devices(MigrationState *); void migration_global_dump(Monitor *mon); -/* True if incomming migration entered POSTCOPY_INCOMING_DISCARD */ +/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */ bool migration_in_incoming_postcopy(void); +/* True if incoming migration entered POSTCOPY_INCOMING_ADVISE */ +bool migration_incoming_postcopy_advised(void); /* True if background snapshot is active */ bool migration_in_bg_snapshot(void); =20 diff --git a/migration/migration.c b/migration/migration.c index 3344c95d26..73225064e1 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2096,6 +2096,13 @@ bool migration_in_incoming_postcopy(void) return ps >=3D POSTCOPY_INCOMING_DISCARD && ps < POSTCOPY_INCOMING_END; } =20 +bool migration_incoming_postcopy_advised(void) +{ + PostcopyState ps =3D postcopy_state_get(); + + return ps >=3D POSTCOPY_INCOMING_ADVISE && ps < POSTCOPY_INCOMING_END; +} + bool migration_in_bg_snapshot(void) { MigrationState *s =3D migrate_get_current(); diff --git a/migration/ram.c b/migration/ram.c index 7f6d5efe8d..b966e148c2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -4150,12 +4150,6 @@ int ram_load_postcopy(QEMUFile *f, int channel) return ret; } =20 -static bool postcopy_is_advised(void) -{ - PostcopyState ps =3D postcopy_state_get(); - return ps >=3D POSTCOPY_INCOMING_ADVISE && ps < POSTCOPY_INCOMING_END; -} - static bool postcopy_is_running(void) { PostcopyState ps =3D postcopy_state_get(); @@ -4226,7 +4220,7 @@ static int ram_load_precopy(QEMUFile *f) MigrationIncomingState *mis =3D migration_incoming_get_current(); int flags =3D 0, ret =3D 0, invalid_flags =3D 0, len =3D 0, i =3D 0; /* ADVISE is earlier, it shows the source has the postcopy capability = on */ - bool postcopy_advised =3D postcopy_is_advised(); + bool postcopy_advised =3D migration_incoming_postcopy_advised(); if (!migrate_use_compression()) { invalid_flags |=3D RAM_SAVE_FLAG_COMPRESS_PAGE; } --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354206; cv=none; d=zohomail.com; s=zohoarc; b=dD0GTkoqaDnu/T/y+w3ovrtkrOQk3/kmk0feRIY+GCH7StTv8SNs6cb/VDM6W0CfIxs2gdNFcyNqYDDH40jXQCJpYZEBj1nc3lxjDUP2QcMtkJhZAe98Oz8tLwUavkv6Z1nKgq+RsDhGpJycLK5cydHdIMEVVErkIc/Kz0aIwN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354206; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DTtSRy6DBbNnmyL3bRVSvZHzrLJgaxvatHJOywuEQV8=; b=GrKEB1IBiceGbpNgHtUEUFDwYqEEDw4Z6kLG969cUt1jeLT5dTFNWBLRYyBNtQJrKYJ0/PnjRsW+3BSJqGCIXWZhMrAs9WXoWD6CBmVRzZgVI+nmW91GcN/CgBWOuIH1keu5/VNEF52h6r9EDqYdPTwcet7j2uEAhxgII+IpAMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354206084604.929349530573; Thu, 2 Feb 2023 08:10:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8K-0000fA-Rs; Thu, 02 Feb 2023 11:08:20 -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 1pNc8G-0000Th-Fi for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:19 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8E-0005FQ-AV for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:16 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-deUzZaSUPwqs94_s2bJLGw-1; Thu, 02 Feb 2023 11:08:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00DBB100F906; Thu, 2 Feb 2023 16:08:12 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2EDF51E5; Thu, 2 Feb 2023 16:08:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354093; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DTtSRy6DBbNnmyL3bRVSvZHzrLJgaxvatHJOywuEQV8=; b=SYaL7kt2FUKSB4gAqaeE4nNVvouXS9bD+iOOjWr9ZbxievRnLuaYBLKVZwjXQUecfu7I/8 wTEv8DocSDa531UAd6i7hPOg3EZ1x7LNoDhjjyourVWqlwGIIbGJ7Wj1Etcy8Cxy03Eua+ pOK0b14K1HpXXp5dJ5EYdKBIfV5HYF4= X-MC-Unique: deUzZaSUPwqs94_s2bJLGw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Michal Privoznik , Peter Xu Subject: [PULL 17/26] virtio-mem: Fail if a memory backend with "prealloc=on" is specified Date: Thu, 2 Feb 2023 17:06:31 +0100 Message-Id: <20230202160640.2300-18-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354208069100003 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand "prealloc=3Don" for the memory backend does not work as expected, as virtio-mem will simply discard all preallocated memory immediately again. In the best case, it's an expensive NOP. In the worst case, it's an unexpected allocation error. Instead, "prealloc=3Don" should be specified for the virtio-mem device only, such that virtio-mem will try preallocating memory before plugging memory dynamically to the guest. Fail if such a memory backend is provided. Tested-by: Michal Privoznik Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- hw/virtio/virtio-mem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 1ed1f5a4af..02f7b5469a 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -772,6 +772,12 @@ static void virtio_mem_device_realize(DeviceState *dev= , Error **errp) error_setg(errp, "'%s' property specifies an unsupported memdev", VIRTIO_MEM_MEMDEV_PROP); return; + } else if (vmem->memdev->prealloc) { + error_setg(errp, "'%s' property specifies a memdev with preallocat= ion" + " enabled: %s. Instead, specify 'prealloc=3Don' for the" + " virtio-mem device. ", VIRTIO_MEM_MEMDEV_PROP, + object_get_canonical_path_component(OBJECT(vmem->memdev= ))); + return; } =20 if ((nb_numa_nodes && vmem->node >=3D nb_numa_nodes) || --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354255; cv=none; d=zohomail.com; s=zohoarc; b=A6RengGbc7VsxMA3W8PQ0BnM9yGuTKo/5pTfp+8q2S7Qb8VQ1ALbnN8ER1OFDYmRldJjcodDYVna96Fw2pbaVsrRTIB2t2pp74TE2hdBMsB0NGvhaEWn1I3BU0YkN36BIcLRewBGBsEiMY6DrTFFYmLDOKjIm1ZfzUxQBLYBl5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354255; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7arfj3QdjtnFGkIbZuw6cq2c+PvzWVH+SNgQFzzJt5I=; b=KLSz5ogM5ra1CzHi4YmtRh6KZ54Gp09N8zKa10H33O6nywKA/8zlcON3mxcEix/+FNGkjVDtMRx31mwmv2vRi9Uc8jKyLzU82vR3L331dlTMmYQ7nof/iUlnBbTwsOMz76Qk9uqWhcSPqgIS1VKmjga3AnyNAFHcvInfXUg05eo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354255775975.3738455435075; Thu, 2 Feb 2023 08:10:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8j-0002LD-Po; Thu, 02 Feb 2023 11:08:45 -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 1pNc8h-000241-QW for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8f-0005Kk-UA for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:43 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-mJXB7BG2MVuc20zjskvFKQ-1; Thu, 02 Feb 2023 11:08:37 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B0B880D0F9; Thu, 2 Feb 2023 16:08:17 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46ADC51E5; Thu, 2 Feb 2023 16:08:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7arfj3QdjtnFGkIbZuw6cq2c+PvzWVH+SNgQFzzJt5I=; b=Q7N9nNyOYanO05Sb2Wp+7f1Kc8kPmcN5/X1qbQnLIdWrbhillEmyEA+6gMz7dGINYg91Ad yEGNNf1isdleJMTTCDAdUQG1ayrd1ylyM3IHdYEGnEBzcoBZBdSQCm5kezM0Chq/5N4/wX bHTqS5lIoB4xocOEfh40UWZh5gG0ND4= X-MC-Unique: mJXB7BG2MVuc20zjskvFKQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu Subject: [PULL 18/26] virtio-mem: Migrate immutable properties early Date: Thu, 2 Feb 2023 17:06:32 +0100 Message-Id: <20230202160640.2300-19-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354256492100005 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand The bitmap and the size are immutable while migration is active: see virtio_mem_is_busy(). We can migrate this information early, before migrating any actual RAM content. Further, all information we need for sanity checks is immutable as well. Having this information in place early will, for example, allow for properly preallocating memory before touching these memory locations during RAM migration: this way, we can make sure that all memory was actually preallocated and that any user errors (e.g., insufficient hugetlb pages) can be handled gracefully. In contrast, usable_region_size and requested_size can theoretically still be modified on the source while the VM is running. Keep migrating these properties the usual, late, way. Use a new device property to keep behavior of compat machines unmodified. Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- include/hw/virtio/virtio-mem.h | 8 ++++++ hw/core/machine.c | 4 ++- hw/virtio/virtio-mem.c | 51 ++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/virtio-mem.h b/include/hw/virtio/virtio-mem.h index 7745cfc1a3..f15e561785 100644 --- a/include/hw/virtio/virtio-mem.h +++ b/include/hw/virtio/virtio-mem.h @@ -31,6 +31,7 @@ OBJECT_DECLARE_TYPE(VirtIOMEM, VirtIOMEMClass, #define VIRTIO_MEM_BLOCK_SIZE_PROP "block-size" #define VIRTIO_MEM_ADDR_PROP "memaddr" #define VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP "unplugged-inaccessible" +#define VIRTIO_MEM_EARLY_MIGRATION_PROP "x-early-migration" #define VIRTIO_MEM_PREALLOC_PROP "prealloc" =20 struct VirtIOMEM { @@ -74,6 +75,13 @@ struct VirtIOMEM { /* whether to prealloc memory when plugging new blocks */ bool prealloc; =20 + /* + * Whether we migrate properties that are immutable while migration is + * active early, before state of other devices and especially, before + * migrating any RAM content. + */ + bool early_migration; + /* notifiers to notify when "size" changes */ NotifierList size_change_notifiers; =20 diff --git a/hw/core/machine.c b/hw/core/machine.c index f7761baab5..b5cd42cd8c 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -41,7 +41,9 @@ #include "hw/virtio/virtio-pci.h" #include "qom/object_interfaces.h" =20 -GlobalProperty hw_compat_7_2[] =3D {}; +GlobalProperty hw_compat_7_2[] =3D { + { "virtio-mem", "x-early-migration", "false" }, +}; const size_t hw_compat_7_2_len =3D G_N_ELEMENTS(hw_compat_7_2); =20 GlobalProperty hw_compat_7_1[] =3D { diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index 02f7b5469a..ca37949df8 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -31,6 +31,8 @@ #include CONFIG_DEVICES #include "trace.h" =20 +static const VMStateDescription vmstate_virtio_mem_device_early; + /* * We only had legacy x86 guests that did not support * VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE. Other targets don't have legacy gu= ests. @@ -878,6 +880,10 @@ static void virtio_mem_device_realize(DeviceState *dev= , Error **errp) =20 host_memory_backend_set_mapped(vmem->memdev, true); vmstate_register_ram(&vmem->memdev->mr, DEVICE(vmem)); + if (vmem->early_migration) { + vmstate_register(VMSTATE_IF(vmem), VMSTATE_INSTANCE_ID_ANY, + &vmstate_virtio_mem_device_early, vmem); + } qemu_register_reset(virtio_mem_system_reset, vmem); =20 /* @@ -899,6 +905,10 @@ static void virtio_mem_device_unrealize(DeviceState *d= ev) */ memory_region_set_ram_discard_manager(&vmem->memdev->mr, NULL); qemu_unregister_reset(virtio_mem_system_reset, vmem); + if (vmem->early_migration) { + vmstate_unregister(VMSTATE_IF(vmem), &vmstate_virtio_mem_device_ea= rly, + vmem); + } vmstate_unregister_ram(&vmem->memdev->mr, DEVICE(vmem)); host_memory_backend_set_mapped(vmem->memdev, false); virtio_del_queue(vdev, 0); @@ -1015,18 +1025,53 @@ static const VMStateDescription vmstate_virtio_mem_= sanity_checks =3D { }, }; =20 +static bool virtio_mem_vmstate_field_exists(void *opaque, int version_id) +{ + const VirtIOMEM *vmem =3D VIRTIO_MEM(opaque); + + /* With early migration, these fields were already migrated. */ + return !vmem->early_migration; +} + static const VMStateDescription vmstate_virtio_mem_device =3D { .name =3D "virtio-mem-device", .minimum_version_id =3D 1, .version_id =3D 1, .priority =3D MIG_PRI_VIRTIO_MEM, .post_load =3D virtio_mem_post_load, + .fields =3D (VMStateField[]) { + VMSTATE_WITH_TMP_TEST(VirtIOMEM, virtio_mem_vmstate_field_exists, + VirtIOMEMMigSanityChecks, + vmstate_virtio_mem_sanity_checks), + VMSTATE_UINT64(usable_region_size, VirtIOMEM), + VMSTATE_UINT64_TEST(size, VirtIOMEM, virtio_mem_vmstate_field_exis= ts), + VMSTATE_UINT64(requested_size, VirtIOMEM), + VMSTATE_BITMAP_TEST(bitmap, VirtIOMEM, virtio_mem_vmstate_field_ex= ists, + 0, bitmap_size), + VMSTATE_END_OF_LIST() + }, +}; + +/* + * Transfer properties that are immutable while migration is active early, + * such that we have have this information around before migrating any RAM + * content. + * + * Note that virtio_mem_is_busy() makes sure these properties can no longer + * change on the migration source until migration completed. + * + * With QEMU compat machines, we transmit these properties later, via + * vmstate_virtio_mem_device instead -- see virtio_mem_vmstate_field_exist= s(). + */ +static const VMStateDescription vmstate_virtio_mem_device_early =3D { + .name =3D "virtio-mem-device-early", + .minimum_version_id =3D 1, + .version_id =3D 1, + .early_setup =3D true, .fields =3D (VMStateField[]) { VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks, vmstate_virtio_mem_sanity_checks), - VMSTATE_UINT64(usable_region_size, VirtIOMEM), VMSTATE_UINT64(size, VirtIOMEM), - VMSTATE_UINT64(requested_size, VirtIOMEM), VMSTATE_BITMAP(bitmap, VirtIOMEM, 0, bitmap_size), VMSTATE_END_OF_LIST() }, @@ -1211,6 +1256,8 @@ static Property virtio_mem_properties[] =3D { DEFINE_PROP_ON_OFF_AUTO(VIRTIO_MEM_UNPLUGGED_INACCESSIBLE_PROP, VirtIO= MEM, unplugged_inaccessible, ON_OFF_AUTO_AUTO), #endif + DEFINE_PROP_BOOL(VIRTIO_MEM_EARLY_MIGRATION_PROP, VirtIOMEM, + early_migration, true), DEFINE_PROP_END_OF_LIST(), }; =20 --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354393; cv=none; d=zohomail.com; s=zohoarc; b=L/9aqHy/iz2GxRaMjgR3Suy3UG+0BKfxUDHucFL4C+IVx8MWQJzpFJ3xvADbbZ80IZiDgnLmb5tMdZ8db/1/YDD8aE/vqopQSZX2iZuSPwGwdxT7QoBG8Mx+xPKovOcVI+hR9kWtItO5jm/EBEMrhtD6hyjPiKfyJfHxIbRgmUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354393; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oRlBuILGEMZyGHaqfHlLNBv2WLhGLyPVAUh7puGRWj4=; b=PF+IVVcbiHfywMggs+BJdrm1YPKVWDxAS+95pXW5uvS/vMH2tnTjiwqmEENTORDBHJjYf9JJ8tImeH6euprJMnXd21ZWvEI+FdINXTI2LcbiE6ELkO3Fembw9OsFYi326xuwUqejKIZ3eBqliGpGbpKROjDAxFWNR5iNCwrn0MI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354393344474.2925640485515; Thu, 2 Feb 2023 08:13:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc8v-0002u1-Jl; Thu, 02 Feb 2023 11:08:57 -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 1pNc8u-0002r7-5k for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8r-0005Ou-IO for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:08:55 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-oPXFwT_GNc-VADxwEd2agg-1; Thu, 02 Feb 2023 11:08:46 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9FD3980652E; Thu, 2 Feb 2023 16:08:22 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F80E51E5; Thu, 2 Feb 2023 16:08:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oRlBuILGEMZyGHaqfHlLNBv2WLhGLyPVAUh7puGRWj4=; b=BfPpMvZnHrMfDvB6yEWVB7q1dgrbg1oIK5L6pBDuJCbjycMOyo1/DIGCN8xT6WiiFBFH5j hUGS3MgqOM+3pG0oU0IqWo6u5y5BBQ111Hp6i7uTB/IDhcoJjZiinfeMXE9SRMlpD4gsHi Ac/grWJFvxdRDs5JO3TWbyUiD6p/gWo= X-MC-Unique: oPXFwT_GNc-VADxwEd2agg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Jing Qi , Peter Xu Subject: [PULL 19/26] virtio-mem: Proper support for preallocation with migration Date: Thu, 2 Feb 2023 17:06:33 +0100 Message-Id: <20230202160640.2300-20-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354394800100002 Content-Type: text/plain; charset="utf-8" From: David Hildenbrand Ordinary memory preallocation runs when QEMU starts up and creates the memory backends, before processing the incoming migration stream. With virtio-mem, we don't know which memory blocks to preallocate before migration started. Now that we migrate the virtio-mem bitmap early, before migrating any RAM content, we can safely preallocate memory for all plugged memory blocks before migrating any RAM content. This is especially relevant for the following cases: (1) User errors With hugetlb/files, if we don't have sufficient backend memory available on the migration destination, we'll crash QEMU (SIGBUS) during RAM migration when running out of backend memory. Preallocating memory before actual RAM migration allows for failing gracefully and informing the user about the setup problem. (2) Excluded memory ranges during migration For example, virtio-balloon free page hinting will exclude some pages from getting migrated. In that case, we won't crash during RAM migration, but later, when running the VM on the destination, which is bad. To fix this for new QEMU machines that migrate the bitmap early, preallocate the memory early, before any RAM migration. Warn with old QEMU machines. Getting postcopy right is a bit tricky, but we essentially now implement the same (problematic) preallocation logic as ordinary preallocation: preallocate memory early and discard it again before precopy starts. During ordinary preallocation, discarding of RAM happens when postcopy is advised. As the state (bitmap) is loaded after postcopy was advised but before postcopy starts listening, we have to discard memory we preallocated immediately again ourselves. Note that nothing (not even hugetlb reservations) guarantees for postcopy that backend memory (especially, hugetlb pages) are still free after they were freed ones while discarding RAM. Still, allocating that memory at least once helps catching some basic setup problems. Before this change, trying to restore a VM when insufficient hugetlb pages are around results in the process crashing to to a "Bus error" (SIGBUS). With this change, QEMU fails gracefully: qemu-system-x86_64: qemu_prealloc_mem: preallocating memory failed: Bad a= ddress qemu-system-x86_64: error while loading state for instance 0x0 of device = '0000:00:03.0/virtio-mem-device-early' qemu-system-x86_64: load of migration failed: Cannot allocate memory And we can even introspect the early migration data, including the bitmap: $ ./scripts/analyze-migration.py -f STATEFILE { "ram (2)": { "section sizes": { "0000:00:03.0/mem0": "0x0000000780000000", "0000:00:04.0/mem1": "0x0000000780000000", "pc.ram": "0x0000000100000000", "/rom@etc/acpi/tables": "0x0000000000020000", "pc.bios": "0x0000000000040000", "0000:00:02.0/e1000.rom": "0x0000000000040000", "pc.rom": "0x0000000000020000", "/rom@etc/table-loader": "0x0000000000001000", "/rom@etc/acpi/rsdp": "0x0000000000001000" } }, "0000:00:03.0/virtio-mem-device-early (51)": { "tmp": "00 00 00 01 40 00 00 00 00 00 00 07 80 00 00 00 00 00 00 00 0= 0 20 00 00 00 00 00 00", "size": "0x0000000040000000", "bitmap": "ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [...] }, "0000:00:04.0/virtio-mem-device-early (53)": { "tmp": "00 00 00 08 c0 00 00 00 00 00 00 07 80 00 00 00 00 00 00 00 0= 0 20 00 00 00 00 00 00", "size": "0x00000001fa400000", "bitmap": "ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff [...] }, [...] Reported-by: Jing Qi Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Peter Xu Reviewed-by: Michael S. Tsirkin Reviewed-by: Juan Quintela S Signed-off-by: David Hildenbrand Signed-off-by: Juan Quintela --- hw/virtio/virtio-mem.c | 87 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/hw/virtio/virtio-mem.c b/hw/virtio/virtio-mem.c index ca37949df8..957fe77dc0 100644 --- a/hw/virtio/virtio-mem.c +++ b/hw/virtio/virtio-mem.c @@ -204,6 +204,30 @@ static int virtio_mem_for_each_unplugged_range(const V= irtIOMEM *vmem, void *arg, return ret; } =20 +static int virtio_mem_for_each_plugged_range(const VirtIOMEM *vmem, void *= arg, + virtio_mem_range_cb cb) +{ + unsigned long first_bit, last_bit; + uint64_t offset, size; + int ret =3D 0; + + first_bit =3D find_first_bit(vmem->bitmap, vmem->bitmap_size); + while (first_bit < vmem->bitmap_size) { + offset =3D first_bit * vmem->block_size; + last_bit =3D find_next_zero_bit(vmem->bitmap, vmem->bitmap_size, + first_bit + 1) - 1; + size =3D (last_bit - first_bit + 1) * vmem->block_size; + + ret =3D cb(vmem, arg, offset, size); + if (ret) { + break; + } + first_bit =3D find_next_bit(vmem->bitmap, vmem->bitmap_size, + last_bit + 2); + } + return ret; +} + /* * Adjust the memory section to cover the intersection with the given rang= e. * @@ -938,6 +962,10 @@ static int virtio_mem_post_load(void *opaque, int vers= ion_id) RamDiscardListener *rdl; int ret; =20 + if (vmem->prealloc && !vmem->early_migration) { + warn_report("Proper preallocation with migration requires a newer = QEMU machine"); + } + /* * We started out with all memory discarded and our memory region is m= apped * into an address space. Replay, now that we updated the bitmap. @@ -957,6 +985,64 @@ static int virtio_mem_post_load(void *opaque, int vers= ion_id) return virtio_mem_restore_unplugged(vmem); } =20 +static int virtio_mem_prealloc_range_cb(const VirtIOMEM *vmem, void *arg, + uint64_t offset, uint64_t size) +{ + void *area =3D memory_region_get_ram_ptr(&vmem->memdev->mr) + offset; + int fd =3D memory_region_get_fd(&vmem->memdev->mr); + Error *local_err =3D NULL; + + qemu_prealloc_mem(fd, area, size, 1, NULL, &local_err); + if (local_err) { + error_report_err(local_err); + return -ENOMEM; + } + return 0; +} + +static int virtio_mem_post_load_early(void *opaque, int version_id) +{ + VirtIOMEM *vmem =3D VIRTIO_MEM(opaque); + RAMBlock *rb =3D vmem->memdev->mr.ram_block; + int ret; + + if (!vmem->prealloc) { + return 0; + } + + /* + * We restored the bitmap and verified that the basic properties + * match on source and destination, so we can go ahead and preallocate + * memory for all plugged memory blocks, before actual RAM migration s= tarts + * touching this memory. + */ + ret =3D virtio_mem_for_each_plugged_range(vmem, NULL, + virtio_mem_prealloc_range_cb); + if (ret) { + return ret; + } + + /* + * This is tricky: postcopy wants to start with a clean slate. On + * POSTCOPY_INCOMING_ADVISE, postcopy code discards all (ordinarily + * preallocated) RAM such that postcopy will work as expected later. + * + * However, we run after POSTCOPY_INCOMING_ADVISE -- but before actual + * RAM migration. So let's discard all memory again. This looks like an + * expensive NOP, but actually serves a purpose: we made sure that we + * were able to allocate all required backend memory once. We cannot + * guarantee that the backend memory we will free will remain free + * until we need it during postcopy, but at least we can catch the + * obvious setup issues this way. + */ + if (migration_incoming_postcopy_advised()) { + if (ram_block_discard_range(rb, 0, qemu_ram_get_used_length(rb))) { + return -EBUSY; + } + } + return 0; +} + typedef struct VirtIOMEMMigSanityChecks { VirtIOMEM *parent; uint64_t addr; @@ -1068,6 +1154,7 @@ static const VMStateDescription vmstate_virtio_mem_de= vice_early =3D { .minimum_version_id =3D 1, .version_id =3D 1, .early_setup =3D true, + .post_load =3D virtio_mem_post_load_early, .fields =3D (VMStateField[]) { VMSTATE_WITH_TMP(VirtIOMEM, VirtIOMEMMigSanityChecks, vmstate_virtio_mem_sanity_checks), --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354466; cv=none; d=zohomail.com; s=zohoarc; b=TbSXRqsfMgHGUCVqmjZ0cApun/d08Fok6dggtsmg9/jo495W3iSy3evh+rdvBYMprfCpbKkl6x7VWIPPGpDXwawrpK3gF1ovUfikzD887XBJCjH7lg0CV0X1r0n0xclGhbydPTwYV2ZI1Ze/200c7btQss0/YEeEbLUmcnLP0wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354466; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1tIlvEvpIhcCLmKUGNAsn0ufT1/cqChm98NkaFvsoeo=; b=ghUSuCTK25/orE08/NtqYlSzTYenqnIjjuCpVzOqz4mRENkNx31x4tta3vEKLmt5FG7foERovTpMfB+DuzEI/vWyBtXyQHbPThuvmAh72Jv19DYEoH0S8IVUfDNdpD6vd+vZ1O7VwjDe4EFglypbnXzZjSergn5aXORYhcj/ORk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354466200426.8370987283645; Thu, 2 Feb 2023 08:14:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9L-0004lm-59; Thu, 02 Feb 2023 11:09:25 -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 1pNc92-0003cD-J9 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc90-0005T1-R9 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:04 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-76-2OgC3SZpONCMl8oqweNAoA-1; Thu, 02 Feb 2023 11:08:51 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 068A0280606B; Thu, 2 Feb 2023 16:08:28 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id E485153AA; Thu, 2 Feb 2023 16:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1tIlvEvpIhcCLmKUGNAsn0ufT1/cqChm98NkaFvsoeo=; b=UA3z0jM6JwaKVrbPqt+ro2lx7YmwfiXMP8dEHn7oknvlHv5eafi4US92NQdXz6vOiAa5cJ g9VGxWJhqoOG1VypXSvrqh4ZqRaaODhYYcRuS1WoR6lg37y2e4AZt1kRuedsTio036OYRN RsvYZbe6B2NBr22e9/paWvNzVunPVFo= X-MC-Unique: 2OgC3SZpONCMl8oqweNAoA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Xu , Leonardo Bras Subject: [PULL 20/26] migration: Show downtime during postcopy phase Date: Thu, 2 Feb 2023 17:06:34 +0100 Message-Id: <20230202160640.2300-21-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354467360100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu The downtime should be displayed during postcopy phase because the switchover phase is done. OTOH it's weird to show "expected downtime" which can confuse what does that mean if the switchover has already happened anyway. This is a slight ABI change on QMP, but I assume it shouldn't affect anyone. Reviewed-by: Leonardo Bras Reviewed-by: Juan Quintela Signed-off-by: Peter Xu Signed-off-by: Juan Quintela --- migration/migration.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 73225064e1..6509203080 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1021,20 +1021,30 @@ bool migration_is_running(int state) } } =20 +static bool migrate_show_downtime(MigrationState *s) +{ + return (s->state =3D=3D MIGRATION_STATUS_COMPLETED) || migration_in_po= stcopy(); +} + static void populate_time_info(MigrationInfo *info, MigrationState *s) { info->has_status =3D true; info->has_setup_time =3D true; info->setup_time =3D s->setup_time; + if (s->state =3D=3D MIGRATION_STATUS_COMPLETED) { info->has_total_time =3D true; info->total_time =3D s->total_time; - info->has_downtime =3D true; - info->downtime =3D s->downtime; } else { info->has_total_time =3D true; info->total_time =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME) - s->start_time; + } + + if (migrate_show_downtime(s)) { + info->has_downtime =3D true; + info->downtime =3D s->downtime; + } else { info->has_expected_downtime =3D true; info->expected_downtime =3D s->expected_downtime; } --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=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 1675354334542283.336371453442; Thu, 2 Feb 2023 08:12:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9U-00061j-80; Thu, 02 Feb 2023 11:09:32 -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 1pNc9J-0004rX-KN for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc9I-0005XW-4C for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:21 -0500 Received: from mimecast-mx02.redhat.com (66.187.233.88 [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-438-sosyOImzMxW_5ShJ5sczkA-1; Thu, 02 Feb 2023 11:09:13 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3BB21804BAE; Thu, 2 Feb 2023 16:08:33 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BFD051FF; Thu, 2 Feb 2023 16:08:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oLTUIKkYKLDqvnCZf7ylBVeUifFGysX8cjMj/PMEy8c=; b=cCoDxL6oXVAdc+bWmeFZqbNcNF9wQ6GBP4jFR84IyriobaXJ+631uZQEqb8gi5+DlYm11M fYzAMm2Ugg6JUaAnM2a2NNUmuDng0TAhzBB7yM7GQU6j2oJOKrdCwq2Pye9dv726Qfchzj sF5veEnotCVTmXcmJw6g5xLh1culOXg= X-MC-Unique: sosyOImzMxW_5ShJ5sczkA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Fiona Ebner , Zhang Chen Subject: [PULL 21/26] migration/rdma: fix return value for qio_channel_rdma_{readv, writev} Date: Thu, 2 Feb 2023 17:06:35 +0100 Message-Id: <20230202160640.2300-22-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1675354336404100001 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner upon errors. As the documentation in include/io/channel.h states, only -1 and QIO_CHANNEL_ERR_BLOCK should be returned upon error. Other values have the potential to confuse the call sites. error_setg is used rather than error_setg_errno, because there are certain code paths where -1 (as a non-errno) is propagated up (e.g. starting from qemu_rdma_block_for_wrid or qemu_rdma_post_recv_control) all the way to qio_channel_rdma_{readv,writev}. Similar to a216ec85b7 ("migration/channel-block: fix return value for qio_channel_block_{readv,writev}"). Suggested-by: Zhang Chen Reviewed-by: Juan Quintela Signed-off-by: Fiona Ebner Signed-off-by: Juan Quintela --- migration/rdma.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/migration/rdma.c b/migration/rdma.c index 94a55dd95b..0ba1668d70 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2785,7 +2785,8 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, rdma =3D qatomic_rcu_read(&rioc->rdmaout); =20 if (!rdma) { - return -EIO; + error_setg(errp, "RDMA control channel output is not set"); + return -1; } =20 CHECK_ERROR_STATE(); @@ -2797,7 +2798,8 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, ret =3D qemu_rdma_write_flush(f, rdma); if (ret < 0) { rdma->error_state =3D ret; - return ret; + error_setg(errp, "qemu_rdma_write_flush returned %d", ret); + return -1; } =20 for (i =3D 0; i < niov; i++) { @@ -2816,7 +2818,8 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, =20 if (ret < 0) { rdma->error_state =3D ret; - return ret; + error_setg(errp, "qemu_rdma_exchange_send returned %d", re= t); + return -1; } =20 data +=3D len; @@ -2867,7 +2870,8 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, rdma =3D qatomic_rcu_read(&rioc->rdmain); =20 if (!rdma) { - return -EIO; + error_setg(errp, "RDMA control channel input is not set"); + return -1; } =20 CHECK_ERROR_STATE(); @@ -2903,7 +2907,8 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, =20 if (ret < 0) { rdma->error_state =3D ret; - return ret; + error_setg(errp, "qemu_rdma_exchange_recv returned %d", ret); + return -1; } =20 /* --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354230; cv=none; d=zohomail.com; s=zohoarc; b=BRFhmQYljbX5AEyy8T6Ds24+u/xkrb8Hp+RY70rJ6KPH0WUqv9p4pgC9SwbbqqEUXxcle8ftvxWZ4TdyqE6M17PGc5EJOzCpkRTReoZuGqwnhqWjazGyLAO3kwAKtSRCAPzVwSISjtKPPVwOwUSWhE/+Wgh/VTlORLwdtKJkj04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354230; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YmJLSmZt2ubSLueF/Ct+KxlmQVT2kWkbO3XpvgWK71g=; b=Zf3JXCZie/WCNrX02EzrPQ/e3SIrEXQIw1xc7E4DcEIXimvkwWcFzccRYMlcznFEgq1vBW8AWGP2j/gb7qDFzw/YNlHqIKa02Dqbg81VsM4DqlOVmSHrtCEYjJhzrWyhOZuDtYjWROrjfkO0NJmD2ILWwPv/97vh5CpGL52KoZM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354230256945.2771772547009; Thu, 2 Feb 2023 08:10:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9P-0005BL-Ro; Thu, 02 Feb 2023 11:09:27 -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 1pNc94-0003xW-HH for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc92-0005Tx-Ny for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:06 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-437-0C2bYT5dMIeZMpYkEX-5Wg-1; Thu, 02 Feb 2023 11:09:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 709B03C0F696; Thu, 2 Feb 2023 16:08:38 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7FEF251FF; Thu, 2 Feb 2023 16:08:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YmJLSmZt2ubSLueF/Ct+KxlmQVT2kWkbO3XpvgWK71g=; b=Eewnk6sgLnlrr0ynWJqhXBWishQGUxlDwdcq72ZDd6igThpxL7ypHilQ7VczXYl7MJfmb7 Advf5lcCKwwM9Anyni+aF3eEBAk0g4i66quvBovzBOouTPr47PBcA80nXLbafTvh+7LYl6 mblCORycn/RBqs5slkFMzHSpX2iUezo= X-MC-Unique: 0C2bYT5dMIeZMpYkEX-5Wg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 22/26] migration: Add canary to VMSTATE_END_OF_LIST Date: Thu, 2 Feb 2023 17:06:36 +0100 Message-Id: <20230202160640.2300-23-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354232203100003 From: "Dr. David Alan Gilbert" We fairly regularly forget VMSTATE_END_OF_LIST markers off descriptions; given that the current check is only for ->name being NULL, sometimes we get unlucky and the code apparently works and no one spots the error. Explicitly add a flag, VMS_END that should be set, and assert it is set during the traversal. Note: This can't go in until we update the copy of vmstate.h in slirp. Suggested-by: Peter Maydell Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/migration/vmstate.h | 7 ++++++- migration/savevm.c | 1 + migration/vmstate.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 28a3b92aa1..084f5e784a 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -147,6 +147,9 @@ enum VMStateFlags { * VMStateField.struct_version_id to tell which version of the * structure we are referencing to use. */ VMS_VSTRUCT =3D 0x8000, + + /* Marker for end of list */ + VMS_END =3D 0x10000 }; =20 typedef enum { @@ -1183,7 +1186,9 @@ extern const VMStateInfo vmstate_info_qlist; VMSTATE_UNUSED_BUFFER(_test, 0, _size) =20 #define VMSTATE_END_OF_LIST() \ - {} + { \ + .flags =3D VMS_END, \ + } =20 int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, int version_id); diff --git a/migration/savevm.c b/migration/savevm.c index 6d985ad4af..5c3e5b1bb5 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -585,6 +585,7 @@ static void dump_vmstate_vmsd(FILE *out_file, field++; first =3D false; } + assert(field->flags =3D=3D VMS_END); fprintf(out_file, "\n%*s]", indent, ""); } if (vmsd->subsections !=3D NULL) { diff --git a/migration/vmstate.c b/migration/vmstate.c index 924494bda3..83ca4c7d3e 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -154,6 +154,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescri= ption *vmsd, } field++; } + assert(field->flags =3D=3D VMS_END); ret =3D vmstate_subsection_load(f, vmsd, opaque); if (ret !=3D 0) { return ret; @@ -408,6 +409,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, } field++; } + assert(field->flags =3D=3D VMS_END); =20 if (vmdesc) { json_writer_end_array(vmdesc); --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354439; cv=none; d=zohomail.com; s=zohoarc; b=FNrWS8EwebysiMfTWp2t2XTHZcJcysFB9HmNaoszstZs5j3jrlJTtUh4JeO3lji/ivWX70FTdCAsKlPBt2lBhKhXRIHqvSE3MsoEfenxw54tZxpG4ScXOcnBTIaB3sHEr82e47OUxcMs9mkdO3C2ttduj8pxfqSIDP+j0qQ7Bnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354439; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZKWrS9/I8tLNhFvOvL6wTWGGmGHs1Q+gINxHteToEV0=; b=hXdyVqV6wzPd5HnS/H9gc5+bR2bk1rQ4nL1ODQ9D5nO2ZLgYx5AtVsKzrzxGkhJ3h7Kb6NAHIAvyTdXBfTXDaItGA3FpZ4fqsVg0OBoUWAYVqMWjBQeOhqR3q0gPVMIbwPZx0JZJnmfuqYEHjnn/2JQ2WzJvvABlF14jmEuJtvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354439362471.09207841621924; Thu, 2 Feb 2023 08:13:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc93-0003eu-1q; Thu, 02 Feb 2023 11:09:05 -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 1pNc91-0003SB-Aa for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc8z-0005SW-Ct for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:02 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-621-weX_QThIPMmXtp2ihToHOA-1; Thu, 02 Feb 2023 11:08:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1589C281DE76; Thu, 2 Feb 2023 16:08:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4C4118EC7; Thu, 2 Feb 2023 16:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354140; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZKWrS9/I8tLNhFvOvL6wTWGGmGHs1Q+gINxHteToEV0=; b=PDVl47Nwb20Nsklkhzc66Tubscl1SefVlJ6eeD156+bLTWU4ywdCR+Kr36uGHgmO2K6yTS mpDCFyJpvqSN9sShNavplPCmAkIWpYy1xxyT+KHXfdrA5B8zZ1z0g6JxyAgftUH8r/D3i/ x4b04aQLUUUDYMhZtS3Jo45B4nYd8Ww= X-MC-Unique: weX_QThIPMmXtp2ihToHOA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Peter Maydell Subject: [PULL 23/26] migration: Perform vmsd structure check during tests Date: Thu, 2 Feb 2023 17:06:37 +0100 Message-Id: <20230202160640.2300-24-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354440921100001 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Perform a check on vmsd structures during test runs in the hope of catching any missing terminators and other simple screwups. Signed-off-by: Dr. David Alan Gilbert Reviewed-by: Peter Maydell Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/savevm.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/migration/savevm.c b/migration/savevm.c index 5c3e5b1bb5..e9cf4999ad 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -66,6 +66,7 @@ #include "net/announce.h" #include "qemu/yank.h" #include "yank_functions.h" +#include "sysemu/qtest.h" =20 const unsigned int postcopy_ram_discard_version; =20 @@ -804,6 +805,42 @@ void unregister_savevm(VMStateIf *obj, const char *ids= tr, void *opaque) } } =20 +/* + * Perform some basic checks on vmsd's at registration + * time. + */ +static void vmstate_check(const VMStateDescription *vmsd) +{ + const VMStateField *field =3D vmsd->fields; + const VMStateDescription **subsection =3D vmsd->subsections; + + if (field) { + while (field->name) { + if (field->flags & (VMS_STRUCT | VMS_VSTRUCT)) { + /* Recurse to sub structures */ + vmstate_check(field->vmsd); + } + /* Carry on */ + field++; + } + /* Check for the end of field list canary */ + if (field->flags !=3D VMS_END) { + error_report("VMSTATE not ending with VMS_END: %s", vmsd->name= ); + g_assert_not_reached(); + } + } + + while (subsection && *subsection) { + /* + * The name of a subsection should start with the name of the + * current object. + */ + assert(!strncmp(vmsd->name, (*subsection)->name, strlen(vmsd->name= ))); + vmstate_check(*subsection); + subsection++; + } +} + int vmstate_register_with_alias_id(VMStateIf *obj, uint32_t instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, @@ -849,6 +886,11 @@ int vmstate_register_with_alias_id(VMStateIf *obj, uin= t32_t instance_id, } else { se->instance_id =3D instance_id; } + + /* Perform a recursive sanity check during the test runs */ + if (qtest_enabled()) { + vmstate_check(vmsd); + } assert(!se->compat || se->instance_id =3D=3D 0); savevm_state_handler_insert(se); return 0; --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354540; cv=none; d=zohomail.com; s=zohoarc; b=EbNLywUOXHAUqvkiYXZdm2FbKFSFkIckKPP6m0biUMr7LXmvL4mIj+9xkw4PqTHmSvPMiklfhUGvpocrL/PA9rSjZBa7NpHoFYPuMZTWg9OFsCpJneVMWjmebzYCtm7v65LprGtxrpBfDK5hV2E2HlcD3uCJzAO/o1ZbyfFZmmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354540; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hudZzsRpagzcLI/XtX7LAUqMBRpe4HeJEe9q7k4gr1A=; b=LFoEbcZb9oKtqY4GNs29JKJV0yJ1H6lioMkuEqOZHSRKCASWv/3PFIKYAf2D/O3lU/sEHYiUFLxsQL7REww0siRKoR2fkLrqND5T90s8q8fE+t6yktuh1q5hFKAeJ91feK1VKk8b36pB24hJ7pP4FORxVFTOy8R9JMsMM/lNK4E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354540801573.0648611246028; Thu, 2 Feb 2023 08:15:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9P-00055N-EV; Thu, 02 Feb 2023 11:09:27 -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 1pNc93-0003os-VC for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc91-0005TV-O9 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:05 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-4ABnJdk8MG22UPpswOJbXA-1; Thu, 02 Feb 2023 11:08:56 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B249738288A1; Thu, 2 Feb 2023 16:08:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8AC9151FF; Thu, 2 Feb 2023 16:08:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354142; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hudZzsRpagzcLI/XtX7LAUqMBRpe4HeJEe9q7k4gr1A=; b=hNGarNspERGbjQp2DV4uECCdB9k6ciVfSKHU+WsJRPusW0nlB9LrSRlR6ioGcEHn4n7lFw IPS9fEuuibQBAI75bzdHpR3sX6qiL4CIMrFCaKK47MHAphrPUK2BzVAql9e47c2gjfrdsB +Uo1/qqwKuU0nnsq7AaTC29BZppS1Ag= X-MC-Unique: 4ABnJdk8MG22UPpswOJbXA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, Zhenzhong Duan , Peter Xu Subject: [PULL 24/26] migration/dirtyrate: Show sample pages only in page-sampling mode Date: Thu, 2 Feb 2023 17:06:38 +0100 Message-Id: <20230202160640.2300-25-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354541970100005 Content-Type: text/plain; charset="utf-8" From: Zhenzhong Duan The value of "Sample Pages" is confusing in mode other than page-sampling. See below: (qemu) calc_dirty_rate -b 10 520 (qemu) info dirty_rate Status: measuring Start Time: 11646834 (ms) Sample Pages: 520 (per GB) Period: 10 (sec) Mode: dirty-bitmap Dirty rate: (not ready) (qemu) info dirty_rate Status: measured Start Time: 11646834 (ms) Sample Pages: 0 (per GB) Period: 10 (sec) Mode: dirty-bitmap Dirty rate: 2 (MB/s) While it's totally useless in dirty-ring and dirty-bitmap mode, fix to show it only in page-sampling mode. Signed-off-by: Zhenzhong Duan Reviewed-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/dirtyrate.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c index 4bfb97fc68..575d48c397 100644 --- a/migration/dirtyrate.c +++ b/migration/dirtyrate.c @@ -714,8 +714,8 @@ void qmp_calc_dirty_rate(int64_t calc_time, mode =3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING; } =20 - if (has_sample_pages && mode =3D=3D DIRTY_RATE_MEASURE_MODE_DIRTY_RING= ) { - error_setg(errp, "either sample-pages or dirty-ring can be specifi= ed."); + if (has_sample_pages && mode !=3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLIN= G) { + error_setg(errp, "sample-pages is used only in page-sampling mode"= ); return; } =20 @@ -785,8 +785,10 @@ void hmp_info_dirty_rate(Monitor *mon, const QDict *qd= ict) DirtyRateStatus_str(info->status)); monitor_printf(mon, "Start Time: %"PRIi64" (ms)\n", info->start_time); - monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n", - info->sample_pages); + if (info->mode =3D=3D DIRTY_RATE_MEASURE_MODE_PAGE_SAMPLING) { + monitor_printf(mon, "Sample Pages: %"PRIu64" (per GB)\n", + info->sample_pages); + } monitor_printf(mon, "Period: %"PRIi64" (sec)\n", info->calc_time); monitor_printf(mon, "Mode: %s\n", --=20 2.39.1 From nobody Wed May 1 21:54:04 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354224; cv=none; d=zohomail.com; s=zohoarc; b=HocdZT2QDZZtSp3uGvWZS2aCouKtWOh68LCzBtqFNElTOEQJhoUWlSE4Aj9e9+acgWxrIJ9Rns7R+BO/5cn3sfmS3PfOQdS7z3EbdgmvdI1eeWqzDE/HhBJDsOilHepPh1HEMcpzjLjTuL5rN71d8vCgvgCQkZ6m+qDfPRdP4lo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354224; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fKPuk3A4ncKmTLyWDDc1BjCWFLugOIjTFFZfMtsDaIk=; b=d7jDu7Ugd3NtrP1EiyUG0fVtXMhYc/xKpD3i6kgCtnabKuB/ZVX3P+8ZQnweR2DIlY2WRTmLlR1NMv5txUzWQhZ9RwrFiAUxzsbMwCnpvOJyLToUpkcx6nCqckcLIIUfFYixFdQAQtxdnCPR5itPmI/9pP31yrfggJr2R5uKW7M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354224477547.4526026165872; Thu, 2 Feb 2023 08:10:24 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9Y-0006be-Oi; Thu, 02 Feb 2023 11:09: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 1pNc9W-0006Lw-P7 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:34 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc9S-0005Yg-JU for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:34 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-XPBuvDVGMQCQ5KtT7-TJAA-1; Thu, 02 Feb 2023 11:09:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD0A7802314; Thu, 2 Feb 2023 16:08:57 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 224B751E5; Thu, 2 Feb 2023 16:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354169; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fKPuk3A4ncKmTLyWDDc1BjCWFLugOIjTFFZfMtsDaIk=; b=E6f7DnfObsd9wVo+iyyRqAyUWCu+8oPd06DLo2OFknsHvx6aeU0tPwGg4Z8yGN+LrCIdin lNSA6y/1AIUR/Cz2Rsim5h2n1l7oT7SY/y6oNaKEfn3V4+4RQEgpnnzwNNWaMKbN1pXFtB 19rVAlJDZu51BAT53WTSlu6GC1RGvNI= X-MC-Unique: XPBuvDVGMQCQ5KtT7-TJAA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, "manish.mishra" , Peter Xu Subject: [PULL 25/26] io: Add support for MSG_PEEK for socket channel Date: Thu, 2 Feb 2023 17:06:39 +0100 Message-Id: <20230202160640.2300-26-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354226245100003 Content-Type: text/plain; charset="utf-8" From: "manish.mishra" MSG_PEEK peeks at the channel, The data is treated as unread and the next read shall still return this data. This support is currently added only for socket class. Extra parameter 'flags' is added to io_readv calls to pass extra read flags like MSG_PEEK. Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrange Reviewed-by: Juan Quintela Suggested-by: Daniel P. Berrange Signed-off-by: manish.mishra Signed-off-by: Juan Quintela --- include/io/channel.h | 6 ++++++ chardev/char-socket.c | 4 ++-- io/channel-buffer.c | 1 + io/channel-command.c | 1 + io/channel-file.c | 1 + io/channel-null.c | 1 + io/channel-socket.c | 19 ++++++++++++++++++- io/channel-tls.c | 1 + io/channel-websock.c | 1 + io/channel.c | 16 ++++++++++++---- migration/channel-block.c | 1 + migration/rdma.c | 1 + scsi/qemu-pr-helper.c | 2 +- tests/qtest/tpm-emu.c | 2 +- tests/unit/test-io-channel-socket.c | 1 + util/vhost-user-server.c | 2 +- 16 files changed, 50 insertions(+), 10 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 78b15f7870..153fbd2904 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -34,6 +34,8 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass, =20 #define QIO_CHANNEL_WRITE_FLAG_ZERO_COPY 0x1 =20 +#define QIO_CHANNEL_READ_FLAG_MSG_PEEK 0x1 + typedef enum QIOChannelFeature QIOChannelFeature; =20 enum QIOChannelFeature { @@ -41,6 +43,7 @@ enum QIOChannelFeature { QIO_CHANNEL_FEATURE_SHUTDOWN, QIO_CHANNEL_FEATURE_LISTEN, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, + QIO_CHANNEL_FEATURE_READ_MSG_PEEK, }; =20 =20 @@ -114,6 +117,7 @@ struct QIOChannelClass { size_t niov, int **fds, size_t *nfds, + int flags, Error **errp); int (*io_close)(QIOChannel *ioc, Error **errp); @@ -188,6 +192,7 @@ void qio_channel_set_name(QIOChannel *ioc, * @niov: the length of the @iov array * @fds: pointer to an array that will received file handles * @nfds: pointer filled with number of elements in @fds on return + * @flags: read flags (QIO_CHANNEL_READ_FLAG_*) * @errp: pointer to a NULL-initialized error object * * Read data from the IO channel, storing it in the @@ -224,6 +229,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp); =20 =20 diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 29ffe5075e..c2265436ac 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -283,11 +283,11 @@ static ssize_t tcp_chr_recv(Chardev *chr, char *buf, = size_t len) if (qio_channel_has_feature(s->ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { ret =3D qio_channel_readv_full(s->ioc, &iov, 1, &msgfds, &msgfds_num, - NULL); + 0, NULL); } else { ret =3D qio_channel_readv_full(s->ioc, &iov, 1, NULL, NULL, - NULL); + 0, NULL); } =20 if (msgfds_num) { diff --git a/io/channel-buffer.c b/io/channel-buffer.c index bf52011be2..8096180f85 100644 --- a/io/channel-buffer.c +++ b/io/channel-buffer.c @@ -54,6 +54,7 @@ static ssize_t qio_channel_buffer_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelBuffer *bioc =3D QIO_CHANNEL_BUFFER(ioc); diff --git a/io/channel-command.c b/io/channel-command.c index 74516252ba..e7edd091af 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -203,6 +203,7 @@ static ssize_t qio_channel_command_readv(QIOChannel *io= c, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); diff --git a/io/channel-file.c b/io/channel-file.c index b67687c2aa..d76663e6ae 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -86,6 +86,7 @@ static ssize_t qio_channel_file_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); diff --git a/io/channel-null.c b/io/channel-null.c index 75e3781507..4fafdb770d 100644 --- a/io/channel-null.c +++ b/io/channel-null.c @@ -60,6 +60,7 @@ qio_channel_null_readv(QIOChannel *ioc, size_t niov, int **fds G_GNUC_UNUSED, size_t *nfds G_GNUC_UNUSED, + int flags, Error **errp) { QIOChannelNull *nioc =3D QIO_CHANNEL_NULL(ioc); diff --git a/io/channel-socket.c b/io/channel-socket.c index b76dca9cc1..7aca84f61a 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -173,6 +173,9 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *i= oc, } #endif =20 + qio_channel_set_feature(QIO_CHANNEL(ioc), + QIO_CHANNEL_FEATURE_READ_MSG_PEEK); + return 0; } =20 @@ -406,6 +409,9 @@ qio_channel_socket_accept(QIOChannelSocket *ioc, } #endif /* WIN32 */ =20 + qio_channel_set_feature(QIO_CHANNEL(cioc), + QIO_CHANNEL_FEATURE_READ_MSG_PEEK); + trace_qio_channel_socket_accept_complete(ioc, cioc, cioc->fd); return cioc; =20 @@ -496,6 +502,7 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); @@ -517,6 +524,10 @@ static ssize_t qio_channel_socket_readv(QIOChannel *io= c, =20 } =20 + if (flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) { + sflags |=3D MSG_PEEK; + } + retry: ret =3D recvmsg(sioc->fd, &msg, sflags); if (ret < 0) { @@ -624,11 +635,17 @@ static ssize_t qio_channel_socket_readv(QIOChannel *i= oc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); ssize_t done =3D 0; ssize_t i; + int sflags =3D 0; + + if (flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) { + sflags |=3D MSG_PEEK; + } =20 for (i =3D 0; i < niov; i++) { ssize_t ret; @@ -636,7 +653,7 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc, ret =3D recv(sioc->fd, iov[i].iov_base, iov[i].iov_len, - 0); + sflags); if (ret < 0) { if (errno =3D=3D EAGAIN) { if (done) { diff --git a/io/channel-tls.c b/io/channel-tls.c index 4ce890a538..c730cb8ec5 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -260,6 +260,7 @@ static ssize_t qio_channel_tls_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); diff --git a/io/channel-websock.c b/io/channel-websock.c index fb4932ade7..a12acc27cf 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -1081,6 +1081,7 @@ static ssize_t qio_channel_websock_readv(QIOChannel *= ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK(ioc); diff --git a/io/channel.c b/io/channel.c index 0640941ac5..a8c7f11649 100644 --- a/io/channel.c +++ b/io/channel.c @@ -52,6 +52,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); @@ -63,7 +64,14 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, return -1; } =20 - return klass->io_readv(ioc, iov, niov, fds, nfds, errp); + if ((flags & QIO_CHANNEL_READ_FLAG_MSG_PEEK) && + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { + error_setg_errno(errp, EINVAL, + "Channel does not support peek read"); + return -1; + } + + return klass->io_readv(ioc, iov, niov, fds, nfds, flags, errp); } =20 =20 @@ -146,7 +154,7 @@ int qio_channel_readv_full_all_eof(QIOChannel *ioc, while ((nlocal_iov > 0) || local_fds) { ssize_t len; len =3D qio_channel_readv_full(ioc, local_iov, nlocal_iov, local_f= ds, - local_nfds, errp); + local_nfds, 0, errp); if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_IN); @@ -284,7 +292,7 @@ ssize_t qio_channel_readv(QIOChannel *ioc, size_t niov, Error **errp) { - return qio_channel_readv_full(ioc, iov, niov, NULL, NULL, errp); + return qio_channel_readv_full(ioc, iov, niov, NULL, NULL, 0, errp); } =20 =20 @@ -303,7 +311,7 @@ ssize_t qio_channel_read(QIOChannel *ioc, Error **errp) { struct iovec iov =3D { .iov_base =3D buf, .iov_len =3D buflen }; - return qio_channel_readv_full(ioc, &iov, 1, NULL, NULL, errp); + return qio_channel_readv_full(ioc, &iov, 1, NULL, NULL, 0, errp); } =20 =20 diff --git a/migration/channel-block.c b/migration/channel-block.c index f4ab53acdb..b7374363c3 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -53,6 +53,7 @@ qio_channel_block_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelBlock *bioc =3D QIO_CHANNEL_BLOCK(ioc); diff --git a/migration/rdma.c b/migration/rdma.c index 0ba1668d70..288eadc2d2 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2857,6 +2857,7 @@ static ssize_t qio_channel_rdma_readv(QIOChannel *ioc, size_t niov, int **fds, size_t *nfds, + int flags, Error **errp) { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 196b78c00d..199227a556 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -614,7 +614,7 @@ static int coroutine_fn prh_read(PRHelperClient *client= , void *buf, int sz, iov.iov_base =3D buf; iov.iov_len =3D sz; n_read =3D qio_channel_readv_full(QIO_CHANNEL(client->ioc), &iov, = 1, - &fds, &nfds, errp); + &fds, &nfds, 0, errp); =20 if (n_read =3D=3D QIO_CHANNEL_ERR_BLOCK) { qio_channel_yield(QIO_CHANNEL(client->ioc), G_IO_IN); diff --git a/tests/qtest/tpm-emu.c b/tests/qtest/tpm-emu.c index 73e0000a2c..f05fe12f01 100644 --- a/tests/qtest/tpm-emu.c +++ b/tests/qtest/tpm-emu.c @@ -115,7 +115,7 @@ void *tpm_emu_ctrl_thread(void *data) int *pfd =3D NULL; size_t nfd =3D 0; =20 - qio_channel_readv_full(ioc, &iov, 1, &pfd, &nfd, &error_abort); + qio_channel_readv_full(ioc, &iov, 1, &pfd, &nfd, 0, &error_abort); cmd =3D be32_to_cpu(cmd); g_assert_cmpint(cmd, =3D=3D, CMD_SET_DATAFD); g_assert_cmpint(nfd, =3D=3D, 1); diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-chann= el-socket.c index b36a5d972a..b964bb202d 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -460,6 +460,7 @@ static void test_io_channel_unix_fd_pass(void) G_N_ELEMENTS(iorecv), &fdrecv, &nfdrecv, + 0, &error_abort); =20 g_assert(nfdrecv =3D=3D G_N_ELEMENTS(fdsend)); diff --git a/util/vhost-user-server.c b/util/vhost-user-server.c index 232984ace6..145eb17c08 100644 --- a/util/vhost-user-server.c +++ b/util/vhost-user-server.c @@ -116,7 +116,7 @@ vu_message_read(VuDev *vu_dev, int conn_fd, VhostUserMs= g *vmsg) * qio_channel_readv_full may have short reads, keeping calling it * until getting VHOST_USER_HDR_SIZE or 0 bytes in total */ - rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, &local_er= r); + rc =3D qio_channel_readv_full(ioc, &iov, 1, &fds, &nfds, 0, &local= _err); if (rc < 0) { if (rc =3D=3D QIO_CHANNEL_ERR_BLOCK) { assert(local_err =3D=3D NULL); --=20 2.39.1 From nobody Wed May 1 21:54:05 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354538; cv=none; d=zohomail.com; s=zohoarc; b=ZBz6MolCwK5Bgu8D1Yz5wjXUWG4v4p69S8hw0oAjTNVrnNnVqDrgBawIR9mVCLY/Mp96OvP3iLauvnz5VqBGINujN/DLGcibLTk6EHTLcTKNoayCYb9Z2HiKPY/+QqEHT0U3aVOSduZzU+wmQ/q7VuooZWsjrCEv55BBj75Mj0Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354538; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0e4q/mah2t6LaHc8IYmZiEvJhspLzN0NjJkVfWmRqy4=; b=cCKs8IqxfzkvsNKjA7SiA32KmgK2mNw0CiIl4GHbDJXlQJKpOyPkd0LCWVHEM9l60PnSZov3jTumnGYf0FElHj0PhEKQznHhk0Zo9oDBNAihOYXvxV7BiKViQ9hV6AsBxlPrinkryFagYA32kZWBpBh/FiuYfGEHsoqHLMKZCuU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1675354538457646.9438196552587; Thu, 2 Feb 2023 08:15:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNc9Q-0005Fe-Fx; Thu, 02 Feb 2023 11:09:28 -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 1pNc9B-0004Sz-2P for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNc97-0005VT-V8 for qemu-devel@nongnu.org; Thu, 02 Feb 2023 11:09:12 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-288-G0wIRsXsOdSjPuzhaF1z2A-1; Thu, 02 Feb 2023 11:09:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CFDF3C14864; Thu, 2 Feb 2023 16:09:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.192.57]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DD3451E5; Thu, 2 Feb 2023 16:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0e4q/mah2t6LaHc8IYmZiEvJhspLzN0NjJkVfWmRqy4=; b=HgD/YIs2ryPCkR1MPxn899llP+y4mg/oOuPsW8idXo2gNiuqIgLDsc9PrMz8Iwgg7kRhBC glmRuewkWIbVpzc0zRTIsv5A0G5k86hmY7UwKYyHh8cwGoZ1raLOXIqzqaNoHRyMfY8qGE wLzq9YhqpFWMWQ57rkfMSgEZY9QaRZE= X-MC-Unique: G0wIRsXsOdSjPuzhaF1z2A-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Richard Henderson , "Michael S. Tsirkin" , Laurent Vivier , Ilya Leoshkevich , Halil Pasic , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Coiby Xu , Eric Farman , Alex Williamson , Christian Borntraeger , Stefan Hajnoczi , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Berger , Eric Blake , Eduardo Habkost , "Dr. David Alan Gilbert" , Thomas Huth , David Hildenbrand , Marcel Apfelbaum , John Snow , Yanan Wang , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Paolo Bonzini , Juan Quintela , Fam Zheng , qemu-s390x@nongnu.org, "manish.mishra" , Peter Xu Subject: [PULL 26/26] migration: check magic value for deciding the mapping of channels Date: Thu, 2 Feb 2023 17:06:40 +0100 Message-Id: <20230202160640.2300-27-quintela@redhat.com> In-Reply-To: <20230202160640.2300-1-quintela@redhat.com> References: <20230202160640.2300-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354540009100003 Content-Type: text/plain; charset="utf-8" From: "manish.mishra" Current logic assumes that channel connections on the destination side are always established in the same order as the source and the first one will always be the main channel followed by the multifid or post-copy preemption channel. This may not be always true, as even if a channel has a connection established on the source side it can be in the pending state on the destination side and a newer connection can be established first. Basically causing out of order mapping of channels on the destination side. Currently, all channels except post-copy preempt send a magic number, this patch uses that magic number to decide the type of channel. This logic is applicable only for precopy(multifd) live migration, as mentioned, the post-copy preempt channel does not send any magic number. Also, tls live migrations already does tls handshake before creating other channels, so this issue is not possible with tls, hence this logic is avoided for tls live migrations. This patch uses read peek to check the magic number of channels so that current data/control stream management remains un-effected. Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrange Reviewed-by: Juan Quintela Suggested-by: Daniel P. Berrange Signed-off-by: manish.mishra Signed-off-by: Juan Quintela --- migration/channel.h | 5 ++++ migration/multifd.h | 2 +- migration/postcopy-ram.h | 2 +- migration/channel.c | 45 +++++++++++++++++++++++++++++++++ migration/migration.c | 54 ++++++++++++++++++++++++++++------------ migration/multifd.c | 19 +++++++------- migration/postcopy-ram.c | 5 +--- 7 files changed, 101 insertions(+), 31 deletions(-) diff --git a/migration/channel.h b/migration/channel.h index 67a461c28a..5bdb8208a7 100644 --- a/migration/channel.h +++ b/migration/channel.h @@ -24,4 +24,9 @@ void migration_channel_connect(MigrationState *s, QIOChannel *ioc, const char *hostname, Error *error_in); + +int migration_channel_read_peek(QIOChannel *ioc, + const char *buf, + const size_t buflen, + Error **errp); #endif diff --git a/migration/multifd.h b/migration/multifd.h index e2802a9ce2..ff3aa2e2e9 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -18,7 +18,7 @@ void multifd_save_cleanup(void); int multifd_load_setup(Error **errp); int multifd_load_cleanup(Error **errp); bool multifd_recv_all_channels_created(void); -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp); +void multifd_recv_new_channel(QIOChannel *ioc, Error **errp); void multifd_recv_sync_main(void); int multifd_send_sync_main(QEMUFile *f); int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); diff --git a/migration/postcopy-ram.h b/migration/postcopy-ram.h index 6147bf7d1d..25881c4127 100644 --- a/migration/postcopy-ram.h +++ b/migration/postcopy-ram.h @@ -190,7 +190,7 @@ enum PostcopyChannels { RAM_CHANNEL_MAX, }; =20 -bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); +void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile); int postcopy_preempt_setup(MigrationState *s, Error **errp); int postcopy_preempt_wait_channel(MigrationState *s); =20 diff --git a/migration/channel.c b/migration/channel.c index 1b0815039f..ca3319a309 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -92,3 +92,48 @@ void migration_channel_connect(MigrationState *s, migrate_fd_connect(s, error); error_free(error); } + + +/** + * @migration_channel_read_peek - Peek at migration channel, without + * actually removing it from channel buffer. + * + * @ioc: the channel object + * @buf: the memory region to read data into + * @buflen: the number of bytes to read in @buf + * @errp: pointer to a NULL-initialized error object + * + * Returns 0 if successful, returns -1 and sets @errp if fails. + */ +int migration_channel_read_peek(QIOChannel *ioc, + const char *buf, + const size_t buflen, + Error **errp) +{ + ssize_t len =3D 0; + struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buflen = }; + + while (true) { + len =3D qio_channel_readv_full(ioc, &iov, 1, NULL, NULL, + QIO_CHANNEL_READ_FLAG_MSG_PEEK, errp); + + if (len <=3D 0 && len !=3D QIO_CHANNEL_ERR_BLOCK) { + error_setg(errp, + "Failed to peek at channel"); + return -1; + } + + if (len =3D=3D buflen) { + break; + } + + /* 1ms sleep. */ + if (qemu_in_coroutine()) { + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 1000000); + } else { + g_usleep(1000); + } + } + + return 0; +} diff --git a/migration/migration.c b/migration/migration.c index 6509203080..f4f7d207f0 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -31,6 +31,7 @@ #include "migration.h" #include "savevm.h" #include "qemu-file.h" +#include "channel.h" #include "migration/vmstate.h" #include "block/block.h" #include "qapi/error.h" @@ -663,10 +664,6 @@ static bool migration_incoming_setup(QEMUFile *f, Erro= r **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); =20 - if (multifd_load_setup(errp) !=3D 0) { - return false; - } - if (!mis->from_src_file) { mis->from_src_file =3D f; } @@ -733,31 +730,56 @@ void migration_ioc_process_incoming(QIOChannel *ioc, = Error **errp) { MigrationIncomingState *mis =3D migration_incoming_get_current(); Error *local_err =3D NULL; - bool start_migration; QEMUFile *f; + bool default_channel =3D true; + uint32_t channel_magic =3D 0; + int ret =3D 0; =20 - if (!mis->from_src_file) { - /* The first connection (multifd may have multiple) */ + if (migrate_use_multifd() && !migrate_postcopy_ram() && + qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_READ_MSG_PEEK)) { + /* + * With multiple channels, it is possible that we receive channels + * out of order on destination side, causing incorrect mapping of + * source channels on destination side. Check channel MAGIC to + * decide type of channel. Please note this is best effort, postco= py + * preempt channel does not send any magic number so avoid it for + * postcopy live migration. Also tls live migration already does + * tls handshake while initializing main channel so with tls this + * issue is not possible. + */ + ret =3D migration_channel_read_peek(ioc, (void *)&channel_magic, + sizeof(channel_magic), &local_er= r); + + if (ret !=3D 0) { + error_propagate(errp, local_err); + return; + } + + default_channel =3D (channel_magic =3D=3D cpu_to_be32(QEMU_VM_FILE= _MAGIC)); + } else { + default_channel =3D !mis->from_src_file; + } + + if (multifd_load_setup(errp) !=3D 0) { + error_setg(errp, "Failed to setup multifd channels"); + return; + } + + if (default_channel) { f =3D qemu_file_new_input(ioc); =20 if (!migration_incoming_setup(f, errp)) { return; } - - /* - * Common migration only needs one channel, so we can start - * right now. Some features need more than one channel, we wait. - */ - start_migration =3D !migration_needs_multiple_sockets(); } else { /* Multiple connections */ assert(migration_needs_multiple_sockets()); if (migrate_use_multifd()) { - start_migration =3D multifd_recv_new_channel(ioc, &local_err); + multifd_recv_new_channel(ioc, &local_err); } else { assert(migrate_postcopy_preempt()); f =3D qemu_file_new_input(ioc); - start_migration =3D postcopy_preempt_new_channel(mis, f); + postcopy_preempt_new_channel(mis, f); } if (local_err) { error_propagate(errp, local_err); @@ -765,7 +787,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Er= ror **errp) } } =20 - if (start_migration) { + if (migration_has_all_channels()) { /* If it's a recovery, we're done */ if (postcopy_try_recover()) { return; diff --git a/migration/multifd.c b/migration/multifd.c index 000ca4d4ec..eeb4fb87ee 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1164,9 +1164,14 @@ int multifd_load_setup(Error **errp) uint32_t page_count =3D MULTIFD_PACKET_SIZE / qemu_target_page_size(); uint8_t i; =20 - if (!migrate_use_multifd()) { + /* + * Return successfully if multiFD recv state is already initialised + * or multiFD is not enabled. + */ + if (multifd_recv_state || !migrate_use_multifd()) { return 0; } + if (!migrate_multi_channels_is_allowed()) { error_setg(errp, "multifd is not supported by current protocol"); return -1; @@ -1227,11 +1232,9 @@ bool multifd_recv_all_channels_created(void) =20 /* * Try to receive all multifd channels to get ready for the migration. - * - Return true and do not set @errp when correctly receiving all channel= s; - * - Return false and do not set @errp when correctly receiving the curren= t one; - * - Return false and set @errp when failing to receive the current channe= l. + * Sets @errp when failing to receive the current channel. */ -bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp) +void multifd_recv_new_channel(QIOChannel *ioc, Error **errp) { MultiFDRecvParams *p; Error *local_err =3D NULL; @@ -1244,7 +1247,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) "failed to receive packet" " via multifd channel %d: ", qatomic_read(&multifd_recv_state->count)); - return false; + return; } trace_multifd_recv_new_channel(id); =20 @@ -1254,7 +1257,7 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) id); multifd_recv_terminate_threads(local_err); error_propagate(errp, local_err); - return false; + return; } p->c =3D ioc; object_ref(OBJECT(ioc)); @@ -1265,6 +1268,4 @@ bool multifd_recv_new_channel(QIOChannel *ioc, Error = **errp) qemu_thread_create(&p->thread, p->name, multifd_recv_thread, p, QEMU_THREAD_JOINABLE); qatomic_inc(&multifd_recv_state->count); - return qatomic_read(&multifd_recv_state->count) =3D=3D - migrate_multifd_channels(); } diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 0c55df0e52..b98e95dab0 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1538,7 +1538,7 @@ void postcopy_unregister_shared_ufd(struct PostCopyFD= *pcfd) } } =20 -bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) +void postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *f= ile) { /* * The new loading channel has its own threads, so it needs to be @@ -1547,9 +1547,6 @@ bool postcopy_preempt_new_channel(MigrationIncomingSt= ate *mis, QEMUFile *file) qemu_file_set_blocking(file, true); mis->postcopy_qemufile_dst =3D file; trace_postcopy_preempt_new_channel(); - - /* Start the migration immediately */ - return true; } =20 /* --=20 2.39.1