From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1668526695788935.8408015856572; Tue, 15 Nov 2022 07:38:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxym-0005r9-MN; Tue, 15 Nov 2022 10:36:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouxyD-0005f5-HN for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:39 -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 1ouxyC-0008HD-2U for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:29 -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-633-sy6U164IPfO3nmut4nREvg-1; Tue, 15 Nov 2022 10:35:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AA5DA857F92; Tue, 15 Nov 2022 15:35:23 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD0292166B2C; Tue, 15 Nov 2022 15:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526527; 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=NgY27LzJ2uT9zxS51v2nfe7D++QJeM61SQkE9yjjQQ8=; b=edgrsMRDn2B/9Hun5hHmEPeDcm0Lg7e3yN2vrw7l1tPDfeWZOaEBDK9vmVAQveUJDAGjc9 Ni6Hoq/xlV/vTvenn2n3F5RhLG9eopa3qmrlAxnX3aQB/KN7uOPSCdYzvwRIGHG0ZlQ2Ph +SYpHJteY5JtbygAJ8Umk8iYjD6psss= X-MC-Unique: sy6U164IPfO3nmut4nREvg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Fiona Ebner Subject: [PULL 01/30] migration/channel-block: fix return value for qio_channel_block_{readv, writev} Date: Tue, 15 Nov 2022 16:34:45 +0100 Message-Id: <20221115153514.28003-2-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1668526697289100003 Content-Type: text/plain; charset="utf-8" From: Fiona Ebner in the error case. The documentation in include/io/channel.h states that -1 or QIO_CHANNEL_ERR_BLOCK should be returned upon error. Simply passing along the return value from the bdrv-functions has the potential to confuse the call sides. Non-blocking mode is not implemented currently, so -1 it is. Signed-off-by: Fiona Ebner Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/channel-block.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/migration/channel-block.c b/migration/channel-block.c index c55c8c93ce..f4ab53acdb 100644 --- a/migration/channel-block.c +++ b/migration/channel-block.c @@ -62,7 +62,8 @@ qio_channel_block_readv(QIOChannel *ioc, qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); ret =3D bdrv_readv_vmstate(bioc->bs, &qiov, bioc->offset); if (ret < 0) { - return ret; + error_setg_errno(errp, -ret, "bdrv_readv_vmstate failed"); + return -1; } =20 bioc->offset +=3D qiov.size; @@ -86,7 +87,8 @@ qio_channel_block_writev(QIOChannel *ioc, qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov); ret =3D bdrv_writev_vmstate(bioc->bs, &qiov, bioc->offset); if (ret < 0) { - return ret; + error_setg_errno(errp, -ret, "bdrv_writev_vmstate failed"); + return -1; } =20 bioc->offset +=3D qiov.size; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527225; cv=none; d=zohomail.com; s=zohoarc; b=nrozIV94/39/FB806Yx64FTNoeK7ZTA9VMRzOOznKBEXtEtfalPNjiPBv1Wo91q++SbV0P0p+dxqcnmugugnTeXCjs8jqhTL7gh+P8AS9rEWUIzTlM6+ns6+ZeT7KKAM1EiYSMFiVPUcumXcXQCUDekGtamnsI50QEN6EVTRNjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527225; 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=KqEMNGfO+9FCgLhL/tSP3g81IW8o7xa3Zcbo6/dqmM0=; b=NcNPRP3ICadcPUJBQPCxjbuuWbSruGXPAiwLsE3/g9fNl9sZl3oQRHsFr7dIRlFP/ix/kjKvZBMX5Z2tGYIWyMQa0TmOyPJssklUUNM5zdot8aITSiuZxpS7TFGflfJpVnTTXHIeUl8Gdx7cjgI6V56MLILVPEatAN9+5jWEIus= 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+importer=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 1668527225108925.7006124228998; Tue, 15 Nov 2022 07:47:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyn-0005rE-30; Tue, 15 Nov 2022 10:36: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 1ouxyH-0005g4-57 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:39 -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 1ouxyF-0008Hv-PV for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:32 -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-112-m7Yt5UsSPyq7Biwyx9HWcQ-1; Tue, 15 Nov 2022 10:35:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ABF1F85A59D; Tue, 15 Nov 2022 15:35:26 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF0E62166B2B; Tue, 15 Nov 2022 15:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526531; 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=KqEMNGfO+9FCgLhL/tSP3g81IW8o7xa3Zcbo6/dqmM0=; b=d7w4iSK0MbILchTjP4K6THh3VvpjEcWckY33egd3E8vfVyehtYZU4unlbiNMPIZZ5rNg5j LYsMZ5+ylDl+ki9X9UcMLnHMy7Hwhlnwf6JZ6JD9GazkHST3L1KGiwKJ6kVjJaoV+bY7oa tOFj5WB5mIxGpvmAqeO2YyW79/fNy8g= X-MC-Unique: m7Yt5UsSPyq7Biwyx9HWcQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Leonardo Bras Subject: [PULL 02/30] migration/multifd/zero-copy: Create helper function for flushing Date: Tue, 15 Nov 2022 16:34:46 +0100 Message-Id: <20221115153514.28003-3-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527225823100001 Content-Type: text/plain; charset="utf-8" From: Leonardo Bras Move flushing code from multifd_send_sync_main() to a new helper, and call it in multifd_send_sync_main(). Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/multifd.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 586ddc9d65..509bbbe3bf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -566,6 +566,23 @@ void multifd_save_cleanup(void) multifd_send_state =3D NULL; } =20 +static int multifd_zero_copy_flush(QIOChannel *c) +{ + int ret; + Error *err =3D NULL; + + ret =3D qio_channel_flush(c, &err); + if (ret < 0) { + error_report_err(err); + return -1; + } + if (ret =3D=3D 1) { + dirty_sync_missed_zero_copy(); + } + + return ret; +} + int multifd_send_sync_main(QEMUFile *f) { int i; @@ -616,17 +633,8 @@ int multifd_send_sync_main(QEMUFile *f) qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 - if (flush_zero_copy && p->c) { - int ret; - Error *err =3D NULL; - - ret =3D qio_channel_flush(p->c, &err); - if (ret < 0) { - error_report_err(err); - return -1; - } else if (ret =3D=3D 1) { - dirty_sync_missed_zero_copy(); - } + if (flush_zero_copy && p->c && (multifd_zero_copy_flush(p->c) < 0)= ) { + return -1; } } for (i =3D 0; i < migrate_multifd_channels(); i++) { --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527630; cv=none; d=zohomail.com; s=zohoarc; b=iqAl4K8h5a9mUs83t465+9thNsoxQ1d6VEY9m/xt8MZwmCifV3Puxcey7rhE8r1olTuHhB/N7gs8BwVGTFttTpg2g3xiGf5dzAtlRan1oDEc3lU3T8inz19V3DLrcn65t2ockrnm4NjHSKa/cXsx9BXJppuT3G1aBGFQdau2aeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527630; 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=tCurYxWEdGHwLhQWrgfdEcGUqQtEfH0e8kBMJDNFNQc=; b=G+3sVGX6cW0hM9aU5qOhupzUjXJEIj07LkRFkWHK2Svzz6pu/ZVJ/2h7j6fpbTqqUQyXWbby5M1AizsuRVt8NKULz3CKhX44N8cNIfLB4ow4dvm3aywO4sMxm3vuAR8aW9oonagF9kcCAnEniasAaKhuGXymCv73o5DGsXz7gy0= 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+importer=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 1668527630175667.3303430799133; Tue, 15 Nov 2022 07:53:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyq-0005tr-8M; Tue, 15 Nov 2022 10:36: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 1ouxyO-0005ji-4V for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:47 -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 1ouxyJ-0008IK-M9 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:38 -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-657-ZbPFLF10M02uhO3RiC3D3w-1; Tue, 15 Nov 2022 10:35:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D4D4F101A54E; Tue, 15 Nov 2022 15:35:29 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 023542166B2C; Tue, 15 Nov 2022 15:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526534; 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=tCurYxWEdGHwLhQWrgfdEcGUqQtEfH0e8kBMJDNFNQc=; b=JdP3KAwkYjiWPEc+Xg0YMR2eJGfQYhDdg27LA3Jk8M77ewu10zTfuwIO9o5lCdlgQePHTv Zgnp3kDGmmd79O92qRN16O4kYYwxiWcb5A7mZE3G9isCLmfOO46uKjb7ZB1l2QwSsSuX0a PuxBAuE9xq1G37MxMwCEw8yBQJN9jmE= X-MC-Unique: ZbPFLF10M02uhO3RiC3D3w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , "manish.mishra" Subject: [PULL 03/30] migration: check magic value for deciding the mapping of channels Date: Tue, 15 Nov 2022 16:34:47 +0100 Message-Id: <20221115153514.28003-4-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-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.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527631378100001 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 MSG_PEEK to check the magic number of channels so that current data/control stream management remains un-effected. v2: TLS does not support MSG_PEEK, so V1 was broken for tls live migrations. For tls live migration, while initializing main channel tls handshake is done before we can create other channels, so this issue is not possible for tls live migrations. In V2 added a check to avoid checking magic number for tls live migration and fallback to older method to decide mapping of channels on destination side. Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: manish.mishra Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/io/channel.h | 25 +++++++++++++++++++++++ migration/multifd.h | 2 +- migration/postcopy-ram.h | 2 +- io/channel-socket.c | 27 ++++++++++++++++++++++++ io/channel.c | 39 +++++++++++++++++++++++++++++++++++ migration/migration.c | 44 +++++++++++++++++++++++++++++----------- migration/multifd.c | 12 ++++------- migration/postcopy-ram.c | 5 +---- 8 files changed, 130 insertions(+), 26 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index c680ee7480..74177aeeea 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -115,6 +115,10 @@ struct QIOChannelClass { int **fds, size_t *nfds, Error **errp); + ssize_t (*io_read_peek)(QIOChannel *ioc, + void *buf, + size_t nbytes, + Error **errp); int (*io_close)(QIOChannel *ioc, Error **errp); GSource * (*io_create_watch)(QIOChannel *ioc, @@ -475,6 +479,27 @@ int qio_channel_write_all(QIOChannel *ioc, size_t buflen, Error **errp); =20 +/** + * qio_channel_read_peek_all: + * @ioc: the channel object + * @buf: the memory region to read in data + * @nbytes: the number of bytes to read + * @errp: pointer to a NULL-initialized error object + * + * Read given @nbytes data from peek of channel into + * memory region @buf. + * + * The function will be blocked until read size is + * equal to requested size. + * + * Returns: 1 if all bytes were read, 0 if end-of-file + * occurs without data, or -1 on error + */ +int qio_channel_read_peek_all(QIOChannel *ioc, + void* buf, + size_t nbytes, + Error **errp); + /** * qio_channel_set_blocking: * @ioc: the channel object diff --git a/migration/multifd.h b/migration/multifd.h index 519f498643..913e4ba274 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/io/channel-socket.c b/io/channel-socket.c index b76dca9cc1..b99f5dfda6 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -705,6 +705,32 @@ static ssize_t qio_channel_socket_writev(QIOChannel *i= oc, } #endif /* WIN32 */ =20 +static ssize_t qio_channel_socket_read_peek(QIOChannel *ioc, + void *buf, + size_t nbytes, + Error **errp) +{ + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); + ssize_t bytes =3D 0; + +retry: + bytes =3D recv(sioc->fd, buf, nbytes, MSG_PEEK); + + if (bytes < 0) { + if (errno =3D=3D EINTR) { + goto retry; + } + if (errno =3D=3D EAGAIN) { + return QIO_CHANNEL_ERR_BLOCK; + } + + error_setg_errno(errp, errno, + "Unable to read from peek of socket"); + return -1; + } + + return bytes; +} =20 #ifdef QEMU_MSG_ZEROCOPY static int qio_channel_socket_flush(QIOChannel *ioc, @@ -902,6 +928,7 @@ static void qio_channel_socket_class_init(ObjectClass *= klass, =20 ioc_klass->io_writev =3D qio_channel_socket_writev; ioc_klass->io_readv =3D qio_channel_socket_readv; + ioc_klass->io_read_peek =3D qio_channel_socket_read_peek; ioc_klass->io_set_blocking =3D qio_channel_socket_set_blocking; ioc_klass->io_close =3D qio_channel_socket_close; ioc_klass->io_shutdown =3D qio_channel_socket_shutdown; diff --git a/io/channel.c b/io/channel.c index 0640941ac5..a2d9b96f3f 100644 --- a/io/channel.c +++ b/io/channel.c @@ -346,6 +346,45 @@ int qio_channel_write_all(QIOChannel *ioc, return qio_channel_writev_all(ioc, &iov, 1, errp); } =20 +int qio_channel_read_peek_all(QIOChannel *ioc, + void* buf, + size_t nbytes, + Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + ssize_t bytes =3D 0; + + if (!klass->io_read_peek) { + error_setg(errp, "Channel does not support read peek"); + return -1; + } + + while (bytes < nbytes) { + bytes =3D klass->io_read_peek(ioc, + buf, + nbytes, + errp); + + if (bytes =3D=3D QIO_CHANNEL_ERR_BLOCK) { + if (qemu_in_coroutine()) { + qio_channel_yield(ioc, G_IO_OUT); + } else { + qio_channel_wait(ioc, G_IO_OUT); + } + continue; + } + if (bytes =3D=3D 0) { + error_setg(errp, + "Unexpected end-of-file on channel"); + return 0; + } + if (bytes < 0) { + return -1; + } + } + + return 1; +} =20 int qio_channel_set_blocking(QIOChannel *ioc, bool enabled, diff --git a/migration/migration.c b/migration/migration.c index 739bb683f3..406a9e2f72 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -733,31 +733,51 @@ 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() && !migration_in_postcopy() && + !migrate_use_tls()) { + /* + * 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 qio_channel_read_peek_all(ioc, (void *)&channel_magic, + sizeof(channel_magic), &local_err); + + if (ret !=3D 1) { + 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 (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 +785,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 509bbbe3bf..b54b6e7528 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -1228,11 +1228,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; @@ -1245,7 +1243,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 @@ -1255,7 +1253,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)); @@ -1266,6 +1264,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 b9a37ef255..f84f783ab4 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -1539,7 +1539,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 @@ -1548,9 +1548,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.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1668526939894305.82024431135096; Tue, 15 Nov 2022 07:42:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyp-0005sT-6i; Tue, 15 Nov 2022 10:36:07 -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 1ouxyP-0005kb-RP for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:47 -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 1ouxyN-0008Iu-Rp for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:41 -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-227-sIq1CAvLPh6UjUVmrMJ-Lg-1; Tue, 15 Nov 2022 10:35:33 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 097D0101A528; Tue, 15 Nov 2022 15:35:33 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 299A72166B2C; Tue, 15 Nov 2022 15:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526539; 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=ZoPVLuHc8bKBMaJocqe53n8qzTbPzXHFovN5EZZS1lo=; b=BMRcYxbfkmeLFD62Qemh3/6hdJpw4i363Y1hizIfSE89eNYYFFNsonXRa5Iqg3ExkSRcz6 nwNmCAHf+UgaqhXrp1L4jBnQzjt5qhBzgpHOvcDA/FpramNzcwtUI9Y5paI4En6Dny05cu 8kIj8kHvQ/RiDOH7ZuXPUjeOG3HD7kc= X-MC-Unique: sIq1CAvLPh6UjUVmrMJ-Lg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Leonardo Bras Subject: [PULL 04/30] multifd: Create page_size fields into both MultiFD{Recv, Send}Params Date: Tue, 15 Nov 2022 16:34:48 +0100 Message-Id: <20221115153514.28003-5-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1668526940546100001 Content-Type: text/plain; charset="utf-8" We were calling qemu_target_page_size() left and right. Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- migration/multifd.h | 4 ++++ migration/multifd-zlib.c | 14 ++++++-------- migration/multifd-zstd.c | 12 +++++------- migration/multifd.c | 18 ++++++++---------- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 913e4ba274..941563c232 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -80,6 +80,8 @@ typedef struct { bool registered_yank; /* packet allocated len */ uint32_t packet_len; + /* guest page size */ + uint32_t page_size; /* multifd flags for sending ram */ int write_flags; =20 @@ -143,6 +145,8 @@ typedef struct { QIOChannel *c; /* packet allocated len */ uint32_t packet_len; + /* guest page size */ + uint32_t page_size; =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; diff --git a/migration/multifd-zlib.c b/migration/multifd-zlib.c index 18213a9513..37770248e1 100644 --- a/migration/multifd-zlib.c +++ b/migration/multifd-zlib.c @@ -116,7 +116,6 @@ static void zlib_send_cleanup(MultiFDSendParams *p, Err= or **errp) static int zlib_send_prepare(MultiFDSendParams *p, Error **errp) { struct zlib_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); z_stream *zs =3D &z->zs; uint32_t out_size =3D 0; int ret; @@ -135,8 +134,8 @@ static int zlib_send_prepare(MultiFDSendParams *p, Erro= r **errp) * with compression. zlib does not guarantee that this is safe, * therefore copy the page before calling deflate(). */ - memcpy(z->buf, p->pages->block->host + p->normal[i], page_size); - zs->avail_in =3D page_size; + memcpy(z->buf, p->pages->block->host + p->normal[i], p->page_size); + zs->avail_in =3D p->page_size; zs->next_in =3D z->buf; =20 zs->avail_out =3D available; @@ -242,12 +241,11 @@ static void zlib_recv_cleanup(MultiFDRecvParams *p) static int zlib_recv_pages(MultiFDRecvParams *p, Error **errp) { struct zlib_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); z_stream *zs =3D &z->zs; uint32_t in_size =3D p->next_packet_size; /* we measure the change of total_out */ uint32_t out_size =3D zs->total_out; - uint32_t expected_size =3D p->normal_num * page_size; + uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; int ret; int i; @@ -274,7 +272,7 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error = **errp) flush =3D Z_SYNC_FLUSH; } =20 - zs->avail_out =3D page_size; + zs->avail_out =3D p->page_size; zs->next_out =3D p->host + p->normal[i]; =20 /* @@ -288,8 +286,8 @@ static int zlib_recv_pages(MultiFDRecvParams *p, Error = **errp) do { ret =3D inflate(zs, flush); } while (ret =3D=3D Z_OK && zs->avail_in - && (zs->total_out - start) < page_size); - if (ret =3D=3D Z_OK && (zs->total_out - start) < page_size) { + && (zs->total_out - start) < p->page_size); + if (ret =3D=3D Z_OK && (zs->total_out - start) < p->page_size) { error_setg(errp, "multifd %u: inflate generated too few output= ", p->id); return -1; diff --git a/migration/multifd-zstd.c b/migration/multifd-zstd.c index d788d309f2..f4a8e1ed1f 100644 --- a/migration/multifd-zstd.c +++ b/migration/multifd-zstd.c @@ -113,7 +113,6 @@ static void zstd_send_cleanup(MultiFDSendParams *p, Err= or **errp) static int zstd_send_prepare(MultiFDSendParams *p, Error **errp) { struct zstd_data *z =3D p->data; - size_t page_size =3D qemu_target_page_size(); int ret; uint32_t i; =20 @@ -128,7 +127,7 @@ static int zstd_send_prepare(MultiFDSendParams *p, Erro= r **errp) flush =3D ZSTD_e_flush; } z->in.src =3D p->pages->block->host + p->normal[i]; - z->in.size =3D page_size; + z->in.size =3D p->page_size; z->in.pos =3D 0; =20 /* @@ -241,8 +240,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) { uint32_t in_size =3D p->next_packet_size; uint32_t out_size =3D 0; - size_t page_size =3D qemu_target_page_size(); - uint32_t expected_size =3D p->normal_num * page_size; + uint32_t expected_size =3D p->normal_num * p->page_size; uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; struct zstd_data *z =3D p->data; int ret; @@ -265,7 +263,7 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) =20 for (i =3D 0; i < p->normal_num; i++) { z->out.dst =3D p->host + p->normal[i]; - z->out.size =3D page_size; + z->out.size =3D p->page_size; z->out.pos =3D 0; =20 /* @@ -279,8 +277,8 @@ static int zstd_recv_pages(MultiFDRecvParams *p, Error = **errp) do { ret =3D ZSTD_decompressStream(z->zds, &z->out, &z->in); } while (ret > 0 && (z->in.size - z->in.pos > 0) - && (z->out.pos < page_size)); - if (ret > 0 && (z->out.pos < page_size)) { + && (z->out.pos < p->page_size)); + if (ret > 0 && (z->out.pos < p->page_size)) { error_setg(errp, "multifd %u: decompressStream buffer too smal= l", p->id); return -1; diff --git a/migration/multifd.c b/migration/multifd.c index b54b6e7528..b32fe7edaf 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -87,15 +87,14 @@ static void nocomp_send_cleanup(MultiFDSendParams *p, E= rror **errp) static int nocomp_send_prepare(MultiFDSendParams *p, Error **errp) { MultiFDPages_t *pages =3D p->pages; - size_t page_size =3D qemu_target_page_size(); =20 for (int i =3D 0; i < p->normal_num; i++) { p->iov[p->iovs_num].iov_base =3D pages->block->host + p->normal[i]; - p->iov[p->iovs_num].iov_len =3D page_size; + p->iov[p->iovs_num].iov_len =3D p->page_size; p->iovs_num++; } =20 - p->next_packet_size =3D p->normal_num * page_size; + p->next_packet_size =3D p->normal_num * p->page_size; p->flags |=3D MULTIFD_FLAG_NOCOMP; return 0; } @@ -139,7 +138,6 @@ static void nocomp_recv_cleanup(MultiFDRecvParams *p) static int nocomp_recv_pages(MultiFDRecvParams *p, Error **errp) { uint32_t flags =3D p->flags & MULTIFD_FLAG_COMPRESSION_MASK; - size_t page_size =3D qemu_target_page_size(); =20 if (flags !=3D MULTIFD_FLAG_NOCOMP) { error_setg(errp, "multifd %u: flags received %x flags expected %x", @@ -148,7 +146,7 @@ static int nocomp_recv_pages(MultiFDRecvParams *p, Erro= r **errp) } for (int i =3D 0; i < p->normal_num; i++) { p->iov[i].iov_base =3D p->host + p->normal[i]; - p->iov[i].iov_len =3D page_size; + p->iov[i].iov_len =3D p->page_size; } return qio_channel_readv_all(p->c, p->iov, p->normal_num, errp); } @@ -281,8 +279,7 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; - size_t page_size =3D qemu_target_page_size(); - uint32_t page_count =3D MULTIFD_PACKET_SIZE / page_size; + uint32_t page_count =3D MULTIFD_PACKET_SIZE / p->page_size; RAMBlock *block; int i; =20 @@ -344,7 +341,7 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams= *p, Error **errp) for (i =3D 0; i < p->normal_num; i++) { uint64_t offset =3D be64_to_cpu(packet->offset[i]); =20 - if (offset > (block->used_length - page_size)) { + if (offset > (block->used_length - p->page_size)) { error_setg(errp, "multifd: offset too long %" PRIu64 " (max " RAM_ADDR_FMT ")", offset, block->used_length); @@ -433,8 +430,7 @@ static int multifd_send_pages(QEMUFile *f) p->packet_num =3D multifd_send_state->packet_num++; multifd_send_state->pages =3D p->pages; p->pages =3D pages; - transferred =3D ((uint64_t) pages->num) * qemu_target_page_size() - + p->packet_len; + transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; qemu_file_acct_rate_limit(f, transferred); ram_counters.multifd_bytes +=3D transferred; ram_counters.transferred +=3D transferred; @@ -947,6 +943,7 @@ int multifd_save_setup(Error **errp) /* We need one extra place for the packet header */ p->iov =3D g_new0(struct iovec, page_count + 1); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_size =3D qemu_target_page_size(); =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1194,6 +1191,7 @@ int multifd_load_setup(Error **errp) p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_size =3D qemu_target_page_size(); } =20 for (i =3D 0; i < thread_count; i++) { --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1668527611410184.10673959089365; Tue, 15 Nov 2022 07:53:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyp-0005sz-Ha; Tue, 15 Nov 2022 10:36:07 -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 1ouxyR-0005ke-0s for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:47 -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 1ouxyO-0008J1-DI for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:42 -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-201-Y6j8LQNrNWeTuHKcJ1-lJQ-1; Tue, 15 Nov 2022 10:35:36 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27BA63C0F7EA; Tue, 15 Nov 2022 15:35:36 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5432B2166B2C; Tue, 15 Nov 2022 15:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526539; 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=NRJB00U1eajSFPXYRkB2Bk91LEyEFNOX/e2zd/Sy/DQ=; b=D+cVqutBK+hBQRJUjaXlMl+u5lNgmVvWD9VrzGn/4NahU4JApBabm9ON8OFiMLBpHucCMz hzfKrGUd12QBBGzzSTc37S3LmR/9/Vjm6SanAPg5DKIPP/VWByWTfUW2PRStbN8dvxJ3mU 2sgmaM8OBziIQpXDieAeitk5MLSxJV8= X-MC-Unique: Y6j8LQNrNWeTuHKcJ1-lJQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Leonardo Bras Subject: [PULL 05/30] multifd: Create page_count fields into both MultiFD{Recv, Send}Params Date: Tue, 15 Nov 2022 16:34:49 +0100 Message-Id: <20221115153514.28003-6-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1668527612110100001 Content-Type: text/plain; charset="utf-8" We were recalculating it left and right. We plan to change that values on next patches. Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- migration/multifd.h | 4 ++++ migration/multifd.c | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 941563c232..ff3aa2e2e9 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -82,6 +82,8 @@ typedef struct { uint32_t packet_len; /* guest page size */ uint32_t page_size; + /* number of pages in a full packet */ + uint32_t page_count; /* multifd flags for sending ram */ int write_flags; =20 @@ -147,6 +149,8 @@ typedef struct { uint32_t packet_len; /* guest page size */ uint32_t page_size; + /* number of pages in a full packet */ + uint32_t page_count; =20 /* syncs main thread and channels */ QemuSemaphore sem_sync; diff --git a/migration/multifd.c b/migration/multifd.c index b32fe7edaf..c40d98ad5c 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -279,7 +279,6 @@ static void multifd_send_fill_packet(MultiFDSendParams = *p) static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) { MultiFDPacket_t *packet =3D p->packet; - uint32_t page_count =3D MULTIFD_PACKET_SIZE / p->page_size; RAMBlock *block; int i; =20 @@ -306,10 +305,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvPara= ms *p, Error **errp) * If we received a packet that is 100 times bigger than expected * just stop migration. It is a magic number. */ - if (packet->pages_alloc > page_count) { + if (packet->pages_alloc > p->page_count) { error_setg(errp, "multifd: received packet " "with size %u and expected a size of %u", - packet->pages_alloc, page_count) ; + packet->pages_alloc, p->page_count) ; return -1; } =20 @@ -944,6 +943,7 @@ int multifd_save_setup(Error **errp) p->iov =3D g_new0(struct iovec, page_count + 1); p->normal =3D g_new0(ram_addr_t, page_count); p->page_size =3D qemu_target_page_size(); + p->page_count =3D page_count; =20 if (migrate_use_zero_copy_send()) { p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; @@ -1191,6 +1191,7 @@ int multifd_load_setup(Error **errp) p->name =3D g_strdup_printf("multifdrecv_%d", i); p->iov =3D g_new0(struct iovec, page_count); p->normal =3D g_new0(ram_addr_t, page_count); + p->page_count =3D page_count; p->page_size =3D qemu_target_page_size(); } =20 --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526890; cv=none; d=zohomail.com; s=zohoarc; b=LNiTPptGyMbIzERQulWPbdj91MfUumP9VGwk63C2jmBTSLmuYzHNfi+kovqW4VyYKiXosgfcyZ/hxa3RF5Gw9koNojDPfCJsQOCkDfu4bkmFf/LMafzQfLpOw3kNhijXnDd8Or24n+0JbcmYAJcMEWrsFqfz77GLD/QZ8In6uVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526890; 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=Q0IBxvLU7+jncQadOjfpnjeGfzdDMllRMxZWahXf5/o=; b=NTIIlav4iJPc4XSO2ZO+CqPi2uaqCDcOC6mCpLEJkGEuPyGA+b5p/TnqkU5QXXfcsQXBwje5Zg6tjeWlrV2jcJQvI2RW7HDROYsamFukReHO8lse5nry2ziglE18KVFWPV5oUnOyGLzn5zBvxKzbdo3QXBvZ9gpA3ewprCAm0I4= 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+importer=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 1668526890016863.3127387251897; Tue, 15 Nov 2022 07:41:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxys-0005xu-PJ; Tue, 15 Nov 2022 10:36:10 -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 1ouxyU-0005l7-Tp for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:53 -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 1ouxyT-0008Ju-Fp for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:46 -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-209-aidbtZ_EM8WZgl931ufUSw-1; Tue, 15 Nov 2022 10:35:41 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 310CD85A5A6; Tue, 15 Nov 2022 15:35:41 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 705022166B2B; Tue, 15 Nov 2022 15:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526544; 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=Q0IBxvLU7+jncQadOjfpnjeGfzdDMllRMxZWahXf5/o=; b=LSDHL6fEv1M4f3kDqNfDfEQbjjH1nBa6sJza+66hLipmC7Ita/QWnlG2NKWRY+AII+7GFi 6BXMbunLeyyqtJQPg8KEj+zvHMK8Q+JtSn7j72aRt5A8LFmEMHUOyj/nUcT4G07goj+Ljq uW/sEJ3N3ZRqZWtxvD3WculVAPljg/c= X-MC-Unique: aidbtZ_EM8WZgl931ufUSw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , David Edmondson , Leonardo Bras Subject: [PULL 06/30] migration: Export ram_transferred_ram() Date: Tue, 15 Nov 2022 16:34:50 +0100 Message-Id: <20221115153514.28003-7-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526892257100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Reviewed-by: David Edmondson Reviewed-by: Leonardo Bras --- migration/ram.h | 2 ++ migration/ram.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/migration/ram.h b/migration/ram.h index c7af65ac74..e844966f69 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -65,6 +65,8 @@ int ram_load_postcopy(QEMUFile *f, int channel); =20 void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 +void ram_transferred_add(uint64_t bytes); + int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_off= set); void ramblock_recv_bitmap_set(RAMBlock *rb, void *host_addr); diff --git a/migration/ram.c b/migration/ram.c index dc1de9ddbc..00a06b2c16 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -422,7 +422,7 @@ uint64_t ram_bytes_remaining(void) =20 MigrationStats ram_counters; =20 -static void ram_transferred_add(uint64_t bytes) +void ram_transferred_add(uint64_t bytes) { if (runstate_is_running()) { ram_counters.precopy_bytes +=3D bytes; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527087; cv=none; d=zohomail.com; s=zohoarc; b=M+V2ImB0ql3NbRRD7rO+jFlSP9sxNvzhyq1lbOlEzMtIeRIB6+BzNj0YNk6BTH0jEtdHwfB7enZVElk4c1I+Ey4dRHD3qTRKkWqVBKeRA6Ov2dz7Cvqk6ZXSxd81rOCpNz4YnSMo6APTQuCi/zNAAK8YQ0N6PFLUkxG7j308k4Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527087; 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=5bcf1jlJmj+rMhBBQmZWe72vDpPf5dtep2kn+uX8o/s=; b=C18mR5ec1reCEwfiRh5MrV3SlyllQVk+c1CzLUtjYXUSPuuiFCIxQ+X8IoXlCh3IZW68wsno/7xqIDiqjeH030+c6UR65M94yIKFBLZvWlRnM9w8emi4jB/fjShdxDVdTfqq+b1OTcpYfmwFT1VmnwDQ8MBjbaMvLeWJAsd9mUE= 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+importer=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 1668527087326106.13469612315191; Tue, 15 Nov 2022 07:44:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyr-0005w0-IF; Tue, 15 Nov 2022 10:36:09 -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 1ouxyZ-0005mU-MI for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:56 -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 1ouxyY-0008Lg-7R for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:51 -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-489-FzqY7oaePjyLHy3uDRnYkA-1; Tue, 15 Nov 2022 10:35:44 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2FB7A1C0754E; Tue, 15 Nov 2022 15:35:44 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 755F92166B2B; Tue, 15 Nov 2022 15:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526548; 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=5bcf1jlJmj+rMhBBQmZWe72vDpPf5dtep2kn+uX8o/s=; b=AOD4ZR5j0LhfgkUTtDS7+dmCzUDaUfIMFnTTF9rS3WEFrhFLgkTEAvB0vg52JSXbWAPtxC kATrZ5mLFaVyIjSPRaIUthK5OZLtlbBBOjehb8PfrFptxOKOgfqCG9GzC/lQPPqoJ9t6qH 1R0myteoenDjjOb2uczCYGJIkN6CJ+k= X-MC-Unique: FzqY7oaePjyLHy3uDRnYkA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , Leonardo Bras Subject: [PULL 07/30] migration: Export ram_release_page() Date: Tue, 15 Nov 2022 16:34:51 +0100 Message-Id: <20221115153514.28003-8-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527089200100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Juan Quintela Reviewed-by: Leonardo Bras --- migration/ram.h | 1 + migration/ram.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/migration/ram.h b/migration/ram.h index e844966f69..038d52f49f 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -66,6 +66,7 @@ int ram_load_postcopy(QEMUFile *f, int channel); void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); =20 void ram_transferred_add(uint64_t bytes); +void ram_release_page(const char *rbname, uint64_t offset); =20 int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_off= set); diff --git a/migration/ram.c b/migration/ram.c index 00a06b2c16..67e41dd2c0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1234,7 +1234,7 @@ static void migration_bitmap_sync_precopy(RAMState *r= s) } } =20 -static void ram_release_page(const char *rbname, uint64_t offset) +void ram_release_page(const char *rbname, uint64_t offset) { if (!migrate_release_ram() || !migration_in_postcopy()) { return; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527725; cv=none; d=zohomail.com; s=zohoarc; b=g2fyIzo0UudeYH8CCsAL+n3v67hZKCCQCDNZr3tpkxSQvdmPikHzCHrAencfBi5ovJYEiiOpqiQOWU8wVEMvY4LP+RLrAUVOUweTo/hp+RLMax7w/klzjj5AyKXJIxD7vHbhcYz2/ojSQKZxxhq5hTgJTCw5UFEIe5a0nrBa48I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527725; 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=qvaUxDudVCAwGQRW2EUntGvs2VEXPayNHnuUyocEiNk=; b=jC3P3sYiNJBitiJ99ufwZcbC4n457dApQ2oJ5PC019XuHp9RGU7r5Z07dFGk78hnfpgd67SmJkWKG3tI88sAaK12x727rEvyo7/+wBeVDzwgowTd/668gTkdrBTUrksuCepHt9ex5utld7Cr/aNw2xN8P7wgtJcslxnP0bOPi7U= 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+importer=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 1668527725157118.09205841071935; Tue, 15 Nov 2022 07:55:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyp-0005sh-9r; Tue, 15 Nov 2022 10:36:07 -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 1ouxyd-0005mv-5S for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:01 -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 1ouxya-0008MF-Rk for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35: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-263-8r77-wXzOdGqr_Zw_xJaDQ-1; Tue, 15 Nov 2022 10:35:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BBB24101A52A; Tue, 15 Nov 2022 15:35:47 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 745372166B2B; Tue, 15 Nov 2022 15:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526552; 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=qvaUxDudVCAwGQRW2EUntGvs2VEXPayNHnuUyocEiNk=; b=A28lICfXiBhgE+Up+eMco2h4X2D94Lg6/VtcOcEuAap1nb4pngUuzVghtLltUCW45RcZek CRtmlEOsR0zdcKz0UVDwfj6vNof83s9JdLOPXfNy5ghduavPZG0AK+jNBlZzasi7BotwLE CEGhGDo9pHb10hOiXhBFMWSLfV+hgA0= X-MC-Unique: 8r77-wXzOdGqr_Zw_xJaDQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , ling xu , Zhou Zhao , Jun Jin Subject: [PULL 08/30] Update AVX512 support for xbzrle_encode_buffer Date: Tue, 15 Nov 2022 16:34:52 +0100 Message-Id: <20221115153514.28003-9-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527725735100003 Content-Type: text/plain; charset="utf-8" From: ling xu This commit updates code of avx512 support for xbzrle_encode_buffer function to accelerate xbzrle encoding speed. Runtime check of avx512 support and benchmark for this feature are added. Compared with C version of xbzrle_encode_buffer function, avx512 version can achieve 50%-70% performance improvement on benchmarking. In addition, if dirty data is randomly located in 4K page, the avx512 version can achieve almost 140% performance gain. Signed-off-by: ling xu Co-authored-by: Zhou Zhao Co-authored-by: Jun Jin Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- meson.build | 16 +++++ migration/xbzrle.h | 4 ++ migration/ram.c | 34 +++++++++- migration/xbzrle.c | 124 ++++++++++++++++++++++++++++++++++ meson_options.txt | 2 + scripts/meson-buildoptions.sh | 14 ++-- 6 files changed, 186 insertions(+), 8 deletions(-) diff --git a/meson.build b/meson.build index cf3e517e56..d0d28f5c9e 100644 --- a/meson.build +++ b/meson.build @@ -2344,6 +2344,22 @@ config_host_data.set('CONFIG_AVX512F_OPT', get_optio= n('avx512f') \ int main(int argc, char *argv[]) { return bar(argv[argc - 1]); } '''), error_message: 'AVX512F not available').allowed()) =20 +config_host_data.set('CONFIG_AVX512BW_OPT', get_option('avx512bw') \ + .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot ena= ble AVX512BW') \ + .require(cc.links(''' + #pragma GCC push_options + #pragma GCC target("avx512bw") + #include + #include + static int bar(void *a) { + + __m512i *x =3D a; + __m512i res=3D _mm512_abs_epi8(*x); + return res[1]; + } + int main(int argc, char *argv[]) { return bar(argv[0]); } + '''), error_message: 'AVX512BW not available').allowed()) + have_pvrdma =3D get_option('pvrdma') \ .require(rdma.found(), error_message: 'PVRDMA requires OpenFabrics libra= ries') \ .require(cc.compiles(gnu_source_prefix + ''' diff --git a/migration/xbzrle.h b/migration/xbzrle.h index a0db507b9c..6feb49160a 100644 --- a/migration/xbzrle.h +++ b/migration/xbzrle.h @@ -18,4 +18,8 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_b= uf, int slen, uint8_t *dst, int dlen); =20 int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen); +#if defined(CONFIG_AVX512BW_OPT) +int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int sl= en, + uint8_t *dst, int dlen); +#endif #endif diff --git a/migration/ram.c b/migration/ram.c index 67e41dd2c0..bb4f08bfed 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -83,6 +83,34 @@ /* 0x80 is reserved in migration.h start with 0x100 next */ #define RAM_SAVE_FLAG_COMPRESS_PAGE 0x100 =20 +int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int, + uint8_t *, int) =3D xbzrle_encode_buffer; +#if defined(CONFIG_AVX512BW_OPT) +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + xbzrle_encode_buffer_func =3D xbzrle_encode_buffer_avx512; + } + } + } +} +#endif + XBZRLECacheStats xbzrle_counters; =20 /* struct contains XBZRLE cache and a static page @@ -802,9 +830,9 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **cur= rent_data, memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE); =20 /* XBZRLE encoding (if there is no overflow) */ - encoded_len =3D xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_= buf, - TARGET_PAGE_SIZE, XBZRLE.encoded_bu= f, - TARGET_PAGE_SIZE); + encoded_len =3D xbzrle_encode_buffer_func(prev_cached_page, XBZRLE.cur= rent_buf, + TARGET_PAGE_SIZE, XBZRLE.encod= ed_buf, + TARGET_PAGE_SIZE); =20 /* * Update the cache contents, so that it corresponds to the data diff --git a/migration/xbzrle.c b/migration/xbzrle.c index 1ba482ded9..05366e86c0 100644 --- a/migration/xbzrle.c +++ b/migration/xbzrle.c @@ -174,3 +174,127 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint= 8_t *dst, int dlen) =20 return d; } + +#if defined(CONFIG_AVX512BW_OPT) +#pragma GCC push_options +#pragma GCC target("avx512bw") +#include +int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int sl= en, + uint8_t *dst, int dlen) +{ + uint32_t zrun_len =3D 0, nzrun_len =3D 0; + int d =3D 0, i =3D 0, num =3D 0; + uint8_t *nzrun_start =3D NULL; + /* add 1 to include residual part in main loop */ + uint32_t count512s =3D (slen >> 6) + 1; + /* countResidual is tail of data, i.e., countResidual =3D slen % 64 */ + uint32_t count_residual =3D slen & 0b111111; + bool never_same =3D true; + uint64_t mask_residual =3D 1; + mask_residual <<=3D count_residual; + mask_residual -=3D 1; + __m512i r =3D _mm512_set1_epi32(0); + + while (count512s) { + if (d + 2 > dlen) { + return -1; + } + + int bytes_to_check =3D 64; + uint64_t mask =3D 0xffffffffffffffff; + if (count512s =3D=3D 1) { + bytes_to_check =3D count_residual; + mask =3D mask_residual; + } + __m512i old_data =3D _mm512_mask_loadu_epi8(r, + mask, old_buf + i); + __m512i new_data =3D _mm512_mask_loadu_epi8(r, + mask, new_buf + i); + uint64_t comp =3D _mm512_cmpeq_epi8_mask(old_data, new_data); + count512s--; + + bool is_same =3D (comp & 0x1); + while (bytes_to_check) { + if (is_same) { + if (nzrun_len) { + d +=3D uleb128_encode_small(dst + d, nzrun_len); + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + nzrun_len =3D 0; + } + /* 64 data at a time for speed */ + if (count512s && (comp =3D=3D 0xffffffffffffffff)) { + i +=3D 64; + zrun_len +=3D 64; + break; + } + never_same =3D false; + num =3D __builtin_ctzll(~comp); + num =3D (num < bytes_to_check) ? num : bytes_to_check; + zrun_len +=3D num; + bytes_to_check -=3D num; + comp >>=3D num; + i +=3D num; + if (bytes_to_check) { + /* still has different data after same data */ + d +=3D uleb128_encode_small(dst + d, zrun_len); + zrun_len =3D 0; + } else { + break; + } + } + if (never_same || zrun_len) { + /* + * never_same only acts if + * data begins with diff in first count512s + */ + d +=3D uleb128_encode_small(dst + d, zrun_len); + zrun_len =3D 0; + never_same =3D false; + } + /* has diff, 64 data at a time for speed */ + if ((bytes_to_check =3D=3D 64) && (comp =3D=3D 0x0)) { + i +=3D 64; + nzrun_len +=3D 64; + break; + } + num =3D __builtin_ctzll(comp); + num =3D (num < bytes_to_check) ? num : bytes_to_check; + nzrun_len +=3D num; + bytes_to_check -=3D num; + comp >>=3D num; + i +=3D num; + if (bytes_to_check) { + /* mask like 111000 */ + d +=3D uleb128_encode_small(dst + d, nzrun_len); + /* overflow */ + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + nzrun_len =3D 0; + is_same =3D true; + } + } + } + + if (nzrun_len !=3D 0) { + d +=3D uleb128_encode_small(dst + d, nzrun_len); + /* overflow */ + if (d + nzrun_len > dlen) { + return -1; + } + nzrun_start =3D new_buf + i - nzrun_len; + memcpy(dst + d, nzrun_start, nzrun_len); + d +=3D nzrun_len; + } + return d; +} +#pragma GCC pop_options +#endif diff --git a/meson_options.txt b/meson_options.txt index 66128178bf..96814dd211 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -104,6 +104,8 @@ option('avx2', type: 'feature', value: 'auto', description: 'AVX2 optimizations') option('avx512f', type: 'feature', value: 'disabled', description: 'AVX512F optimizations') +option('avx512bw', type: 'feature', value: 'auto', + description: 'AVX512BW optimizations') option('keyring', type: 'feature', value: 'auto', description: 'Linux keyring support') =20 diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 2cb0de5601..bcb5d854a5 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -40,7 +40,8 @@ meson_options_help() { printf "%s\n" ' --enable-trace-backends=3DCHOICES' printf "%s\n" ' Set available tracing backends= [log] (choices:' printf "%s\n" ' dtrace/ftrace/log/nop/simple/s= yslog/ust)' - printf "%s\n" ' --firmwarepath=3DVALUES search PATH for firmware fil= es [share/qemu-firmware]' + printf "%s\n" ' --firmwarepath=3DVALUES search PATH for firmware fil= es [share/qemu-' + printf "%s\n" ' firmware]' printf "%s\n" ' --iasl=3DVALUE Path to ACPI disassembler' printf "%s\n" ' --includedir=3DVALUE Header file directory [inclu= de]' printf "%s\n" ' --interp-prefix=3DVALUE where to find shared librari= es etc., use %M for' @@ -66,6 +67,7 @@ meson_options_help() { printf "%s\n" ' attr attr/xattr support' printf "%s\n" ' auth-pam PAM access control' printf "%s\n" ' avx2 AVX2 optimizations' + printf "%s\n" ' avx512bw AVX512BW optimizations' printf "%s\n" ' avx512f AVX512F optimizations' printf "%s\n" ' blkio libblkio block device driver' printf "%s\n" ' bochs bochs image format support' @@ -155,6 +157,8 @@ meson_options_help() { printf "%s\n" ' usb-redir libusbredir support' printf "%s\n" ' vde vde network backend support' printf "%s\n" ' vdi vdi image format support' + printf "%s\n" ' vduse-blk-export' + printf "%s\n" ' VDUSE block export support' printf "%s\n" ' vfio-user-server' printf "%s\n" ' vfio-user server support' printf "%s\n" ' vhost-crypto vhost-user crypto backend support' @@ -163,8 +167,6 @@ meson_options_help() { printf "%s\n" ' vhost-user vhost-user backend support' printf "%s\n" ' vhost-user-blk-server' printf "%s\n" ' build vhost-user-blk server' - printf "%s\n" ' vduse-blk-export' - printf "%s\n" ' VDUSE block export support' printf "%s\n" ' vhost-vdpa vhost-vdpa kernel backend support' printf "%s\n" ' virglrenderer virgl rendering support' printf "%s\n" ' virtfs virtio-9p support' @@ -193,6 +195,8 @@ _meson_option_parse() { --disable-auth-pam) printf "%s" -Dauth_pam=3Ddisabled ;; --enable-avx2) printf "%s" -Davx2=3Denabled ;; --disable-avx2) printf "%s" -Davx2=3Ddisabled ;; + --enable-avx512bw) printf "%s" -Davx512bw=3Denabled ;; + --disable-avx512bw) printf "%s" -Davx512bw=3Ddisabled ;; --enable-avx512f) printf "%s" -Davx512f=3Denabled ;; --disable-avx512f) printf "%s" -Davx512f=3Ddisabled ;; --enable-gcov) printf "%s" -Db_coverage=3Dtrue ;; @@ -426,6 +430,8 @@ _meson_option_parse() { --disable-vde) printf "%s" -Dvde=3Ddisabled ;; --enable-vdi) printf "%s" -Dvdi=3Denabled ;; --disable-vdi) printf "%s" -Dvdi=3Ddisabled ;; + --enable-vduse-blk-export) printf "%s" -Dvduse_blk_export=3Denabled ;; + --disable-vduse-blk-export) printf "%s" -Dvduse_blk_export=3Ddisabled = ;; --enable-vfio-user-server) printf "%s" -Dvfio_user_server=3Denabled ;; --disable-vfio-user-server) printf "%s" -Dvfio_user_server=3Ddisabled = ;; --enable-vhost-crypto) printf "%s" -Dvhost_crypto=3Denabled ;; @@ -438,8 +444,6 @@ _meson_option_parse() { --disable-vhost-user) printf "%s" -Dvhost_user=3Ddisabled ;; --enable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server=3D= enabled ;; --disable-vhost-user-blk-server) printf "%s" -Dvhost_user_blk_server= =3Ddisabled ;; - --enable-vduse-blk-export) printf "%s" -Dvduse_blk_export=3Denabled ;; - --disable-vduse-blk-export) printf "%s" -Dvduse_blk_export=3Ddisabled = ;; --enable-vhost-vdpa) printf "%s" -Dvhost_vdpa=3Denabled ;; --disable-vhost-vdpa) printf "%s" -Dvhost_vdpa=3Ddisabled ;; --enable-virglrenderer) printf "%s" -Dvirglrenderer=3Denabled ;; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527692; cv=none; d=zohomail.com; s=zohoarc; b=X6jZZ1tdHZxKPeYWCAxMAL5A7BVNzZV156sWpRHPTV42lkOOtA8z7b3w2r623XPxJDIbp+1NlRywMTSfwrgA/6yNuhVQTbYXfnY/LHiC4Vr6Lkv6PREHCCaCRDl9xWQKjNPGKHlTayLBfjh3Jrjwj9DneDUT8IRxXPdwD/gj76s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527692; 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=Yb6b+jRmG/szR2Mftgr4Hjn9CkJRVD9GdwEO0m1vzdg=; b=g3NGp8GD4FiJ3tAcHYkwD3UsuUGz7ra0EVxq0VYKLeKv87JhFku7j18952MbShPqfmw7dt2hWI6aK9VPIPh6zP5VIKo+GzwiXQj5p+7LWMB0AfE6SeHHx2zr57x7HGP3U8t3xdJrnpipnLG2Eq1vvngxGI4pFCsPTeUHAy0YFtM= 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+importer=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 16685276924751002.3512923079466; Tue, 15 Nov 2022 07:54:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyq-0005vN-UR; Tue, 15 Nov 2022 10:36: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 1ouxyg-0005nZ-Bk for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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 1ouxyd-0008Mk-NL for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:57 -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-512-FAXh8hfPNYupS8rpCbuMng-1; Tue, 15 Nov 2022 10:35:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 614E33C0F7F3; Tue, 15 Nov 2022 15:35:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D0662166B2B; Tue, 15 Nov 2022 15:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526555; 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=Yb6b+jRmG/szR2Mftgr4Hjn9CkJRVD9GdwEO0m1vzdg=; b=Kv1K2nsdo+KDQt31C623lFbwXIc0ZsD11afiIxTXKS8DnLoOkm5bL/8Kb/sMPT5ZMuJ6Tt P6z7kPsLJH+heqquuGOr7gqSOaMrjUk514T7s+XdduqqqyFRVuu7kYUNAd2Z4bKpcmU+DL atUXuIMA4VbC+O7SdSqFe1hdld0AOAE= X-MC-Unique: FAXh8hfPNYupS8rpCbuMng-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng , ling xu , Zhou Zhao , Jun Jin Subject: [PULL 09/30] Unit test code and benchmark code Date: Tue, 15 Nov 2022 16:34:53 +0100 Message-Id: <20221115153514.28003-10-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527693754100003 Content-Type: text/plain; charset="utf-8" From: ling xu Unit test code is in test-xbzrle.c, and benchmark code is in xbzrle-bench.c for performance benchmarking. Signed-off-by: ling xu Co-authored-by: Zhou Zhao Co-authored-by: Jun Jin Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- tests/bench/xbzrle-bench.c | 465 +++++++++++++++++++++++++++++++++++++ tests/unit/test-xbzrle.c | 39 +++- tests/bench/meson.build | 4 + 3 files changed, 503 insertions(+), 5 deletions(-) create mode 100644 tests/bench/xbzrle-bench.c diff --git a/tests/bench/xbzrle-bench.c b/tests/bench/xbzrle-bench.c new file mode 100644 index 0000000000..d71397e6f4 --- /dev/null +++ b/tests/bench/xbzrle-bench.c @@ -0,0 +1,465 @@ +/* + * Xor Based Zero Run Length Encoding unit tests. + * + * Copyright 2013 Red Hat, Inc. and/or its affiliates + * + * Authors: + * Orit Wasserman + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ +#include "qemu/osdep.h" +#include "qemu/cutils.h" +#include "../migration/xbzrle.h" + +#define XBZRLE_PAGE_SIZE 4096 + +#if defined(CONFIG_AVX512BW_OPT) +static bool is_cpu_support_avx512bw; +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + is_cpu_support_avx512bw =3D false; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + is_cpu_support_avx512bw =3D true; + } + } + } + return ; +} +#endif + +struct ResTime { + float t_raw; + float t_512; +}; + +static void encode_decode_zero(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0; + int dlen =3D 0, dlen512 =3D 0; + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + buffer[1000 + i] =3D i; + buffer512[1000 + i] =3D i; + } + + buffer[1000 + diff_len + 3] =3D 103; + buffer[1000 + diff_len + 5] =3D 105; + + buffer512[1000 + diff_len + 3] =3D 103; + buffer512[1000 + diff_len + 5] =3D 105; + + /* encode zero page */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE, compre= ssed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(buffer512, buffer512, XBZRLE_P= AGE_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(buffer512); + g_free(compressed512); + +} + +static void test_encode_decode_zero_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_zero(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Zero test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_unchanged(struct ResTime *res) +{ + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0; + int dlen =3D 0, dlen512 =3D 0; + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + test[1000 + i] =3D i + 4; + test512[1000 + i] =3D i + 4; + } + + test[1000 + diff_len + 3] =3D 107; + test[1000 + diff_len + 5] =3D 109; + + test512[1000 + diff_len + 3] =3D 107; + test512[1000 + diff_len + 5] =3D 109; + + /* test unchanged buffer */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE, compressed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, test512, XBZRLE_PAGE_= SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(test); + g_free(compressed); + g_free(test512); + g_free(compressed512); + +} + +static void test_encode_decode_unchanged_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_unchanged(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Unchanged test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_1_byte(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + int dlen =3D 0, rc =3D 0, dlen512 =3D 0, rc512 =3D 0; + uint8_t buf[2]; + uint8_t buf512[2]; + + test[XBZRLE_PAGE_SIZE - 1] =3D 1; + test512[XBZRLE_PAGE_SIZE - 1] =3D 1; + + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(dlen =3D=3D (uleb128_encode_small(&buf[0], 4095) + 2)); + + rc =3D xbzrle_decode_buffer(compressed, dlen, buffer, XBZRLE_PAGE_SIZE= ); + g_assert(rc =3D=3D XBZRLE_PAGE_SIZE); + g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(buffer512, test512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(dlen512 =3D=3D (uleb128_encode_small(&buf512[0], 4095) + 2)); + + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, buffer512, + XBZRLE_PAGE_SIZE); + g_assert(rc512 =3D=3D XBZRLE_PAGE_SIZE); + g_assert(memcmp(test512, buffer512, XBZRLE_PAGE_SIZE) =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_1_byte_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_1_byte(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("1 byte test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_overflow(struct ResTime *res) +{ + uint8_t *compressed =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + + for (i =3D 0; i < XBZRLE_PAGE_SIZE / 2 - 1; i++) { + test[i * 2] =3D 1; + test512[i * 2] =3D 1; + } + + /* encode overflow */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + rc =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + g_assert(rc =3D=3D -1); + + t_start512 =3D clock(); + rc512 =3D xbzrle_encode_buffer_avx512(buffer512, test512, XBZRLE_PAGE_= SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + g_assert(rc512 =3D=3D -1); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_overflow_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_overflow(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Overflow test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_range_avx512(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + int dlen =3D 0, dlen512 =3D 0; + + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1006); + + for (i =3D diff_len; i > 0; i--) { + buffer[1000 + i] =3D i; + test[1000 + i] =3D i + 4; + buffer512[1000 + i] =3D i; + test512[1000 + i] =3D i + 4; + } + + buffer[1000 + diff_len + 3] =3D 103; + test[1000 + diff_len + 3] =3D 107; + + buffer[1000 + diff_len + 5] =3D 105; + test[1000 + diff_len + 5] =3D 109; + + buffer512[1000 + diff_len + 3] =3D 103; + test512[1000 + diff_len + 3] =3D 107; + + buffer512[1000 + diff_len + 5] =3D 105; + test512[1000 + diff_len + 5] =3D 109; + + /* test encode/decode */ + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); + g_assert(rc < XBZRLE_PAGE_SIZE); + g_assert(memcmp(test, buffer, XBZRLE_PAGE_SIZE) =3D=3D 0); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, buffer512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, test512, XBZRLE= _PAGE_SIZE); + g_assert(rc512 < XBZRLE_PAGE_SIZE); + g_assert(memcmp(test512, buffer512, XBZRLE_PAGE_SIZE) =3D=3D 0); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_range_avx512(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Encode decode test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +static void encode_decode_random(struct ResTime *res) +{ + uint8_t *buffer =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *buffer512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + uint8_t *compressed512 =3D g_malloc(XBZRLE_PAGE_SIZE); + uint8_t *test512 =3D g_malloc0(XBZRLE_PAGE_SIZE); + int i =3D 0, rc =3D 0, rc512 =3D 0; + int dlen =3D 0, dlen512 =3D 0; + + int diff_len =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1); + /* store the index of diff */ + int dirty_index[diff_len]; + for (int j =3D 0; j < diff_len; j++) { + dirty_index[j] =3D g_test_rand_int_range(0, XBZRLE_PAGE_SIZE - 1); + } + for (i =3D diff_len - 1; i >=3D 0; i--) { + buffer[dirty_index[i]] =3D i; + test[dirty_index[i]] =3D i + 4; + buffer512[dirty_index[i]] =3D i; + test512[dirty_index[i]] =3D i + 4; + } + + time_t t_start, t_end, t_start512, t_end512; + t_start =3D clock(); + dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + XBZRLE_PAGE_SIZE); + t_end =3D clock(); + float time_val =3D difftime(t_end, t_start); + rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); + g_assert(rc < XBZRLE_PAGE_SIZE); + + t_start512 =3D clock(); + dlen512 =3D xbzrle_encode_buffer_avx512(test512, buffer512, XBZRLE_PAG= E_SIZE, + compressed512, XBZRLE_PAGE_SIZE); + t_end512 =3D clock(); + float time_val512 =3D difftime(t_end512, t_start512); + rc512 =3D xbzrle_decode_buffer(compressed512, dlen512, test512, XBZRLE= _PAGE_SIZE); + g_assert(rc512 < XBZRLE_PAGE_SIZE); + + res->t_raw =3D time_val; + res->t_512 =3D time_val512; + + g_free(buffer); + g_free(compressed); + g_free(test); + g_free(buffer512); + g_free(compressed512); + g_free(test512); + +} + +static void test_encode_decode_random_avx512(void) +{ + int i; + float time_raw =3D 0.0, time_512 =3D 0.0; + struct ResTime res; + for (i =3D 0; i < 10000; i++) { + encode_decode_random(&res); + time_raw +=3D res.t_raw; + time_512 +=3D res.t_512; + } + printf("Random test:\n"); + printf("Raw xbzrle_encode time is %f ms\n", time_raw); + printf("512 xbzrle_encode time is %f ms\n", time_512); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + g_test_rand_int(); + #if defined(CONFIG_AVX512BW_OPT) + if (likely(is_cpu_support_avx512bw)) { + g_test_add_func("/xbzrle/encode_decode_zero", test_encode_decode_z= ero_avx512); + g_test_add_func("/xbzrle/encode_decode_unchanged", + test_encode_decode_unchanged_avx512); + g_test_add_func("/xbzrle/encode_decode_1_byte", test_encode_decode= _1_byte_avx512); + g_test_add_func("/xbzrle/encode_decode_overflow", + test_encode_decode_overflow_avx512); + g_test_add_func("/xbzrle/encode_decode", test_encode_decode_avx512= ); + g_test_add_func("/xbzrle/encode_decode_random", test_encode_decode= _random_avx512); + } + #endif + return g_test_run(); +} diff --git a/tests/unit/test-xbzrle.c b/tests/unit/test-xbzrle.c index ef951b6e54..547046d093 100644 --- a/tests/unit/test-xbzrle.c +++ b/tests/unit/test-xbzrle.c @@ -16,6 +16,35 @@ =20 #define XBZRLE_PAGE_SIZE 4096 =20 +int (*xbzrle_encode_buffer_func)(uint8_t *, uint8_t *, int, + uint8_t *, int) =3D xbzrle_encode_buffer; +#if defined(CONFIG_AVX512BW_OPT) +#include "qemu/cpuid.h" +static void __attribute__((constructor)) init_cpu_flag(void) +{ + unsigned max =3D __get_cpuid_max(0, NULL); + int a, b, c, d; + if (max >=3D 1) { + __cpuid(1, a, b, c, d); + /* We must check that AVX is not just available, but usable. */ + if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >=3D 7) { + int bv; + __asm("xgetbv" : "=3Da"(bv), "=3Dd"(d) : "c"(0)); + __cpuid_count(7, 0, a, b, c, d); + /* 0xe6: + * XCR0[7:5] =3D 111b (OPMASK state, upper 256-bit of ZMM0-ZMM= 15 + * and ZMM16-ZMM31 state are enabled by OS) + * XCR0[2:1] =3D 11b (XMM state and YMM state are enabled by O= S) + */ + if ((bv & 0xe6) =3D=3D 0xe6 && (b & bit_AVX512BW)) { + xbzrle_encode_buffer_func =3D xbzrle_encode_buffer_avx512; + } + } + } + return ; +} +#endif + static void test_uleb(void) { uint32_t i, val; @@ -54,7 +83,7 @@ static void test_encode_decode_zero(void) buffer[1000 + diff_len + 5] =3D 105; =20 /* encode zero page */ - dlen =3D xbzrle_encode_buffer(buffer, buffer, XBZRLE_PAGE_SIZE, compre= ssed, + dlen =3D xbzrle_encode_buffer_func(buffer, buffer, XBZRLE_PAGE_SIZE, c= ompressed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D 0); =20 @@ -78,7 +107,7 @@ static void test_encode_decode_unchanged(void) test[1000 + diff_len + 5] =3D 109; =20 /* test unchanged buffer */ - dlen =3D xbzrle_encode_buffer(test, test, XBZRLE_PAGE_SIZE, compressed, + dlen =3D xbzrle_encode_buffer_func(test, test, XBZRLE_PAGE_SIZE, compr= essed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D 0); =20 @@ -96,7 +125,7 @@ static void test_encode_decode_1_byte(void) =20 test[XBZRLE_PAGE_SIZE - 1] =3D 1; =20 - dlen =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compress= ed, + dlen =3D xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, com= pressed, XBZRLE_PAGE_SIZE); g_assert(dlen =3D=3D (uleb128_encode_small(&buf[0], 4095) + 2)); =20 @@ -121,7 +150,7 @@ static void test_encode_decode_overflow(void) } =20 /* encode overflow */ - rc =3D xbzrle_encode_buffer(buffer, test, XBZRLE_PAGE_SIZE, compressed, + rc =3D xbzrle_encode_buffer_func(buffer, test, XBZRLE_PAGE_SIZE, compr= essed, XBZRLE_PAGE_SIZE); g_assert(rc =3D=3D -1); =20 @@ -152,7 +181,7 @@ static void encode_decode_range(void) test[1000 + diff_len + 5] =3D 109; =20 /* test encode/decode */ - dlen =3D xbzrle_encode_buffer(test, buffer, XBZRLE_PAGE_SIZE, compress= ed, + dlen =3D xbzrle_encode_buffer_func(test, buffer, XBZRLE_PAGE_SIZE, com= pressed, XBZRLE_PAGE_SIZE); =20 rc =3D xbzrle_decode_buffer(compressed, dlen, test, XBZRLE_PAGE_SIZE); diff --git a/tests/bench/meson.build b/tests/bench/meson.build index 279a8fcc33..daefead58d 100644 --- a/tests/bench/meson.build +++ b/tests/bench/meson.build @@ -3,6 +3,10 @@ qht_bench =3D executable('qht-bench', sources: 'qht-bench.c', dependencies: [qemuutil]) =20 +xbzrle_bench =3D executable('xbzrle-bench', + sources: 'xbzrle-bench.c', + dependencies: [qemuutil,migration]) + executable('atomic_add-bench', sources: files('atomic_add-bench.c'), dependencies: [qemuutil], --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527919; cv=none; d=zohomail.com; s=zohoarc; b=HKaKKh09CQQOVT1E3HpZHmOWPnRWksAeT3QAcjqxDRwNZSrUL/H5Jpuv9oWNCqt8cyDl7a4F+fkKD1/cmjrA/vwqnC5zhxX+x9FDt1MNin7VE8DZ+r5OepBIiDN1TG+RBoIpG+xxWhib1YnGAG/UU4ojQo2MVApXfnG/sdWgNf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527919; 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=8sTZ2tLPTwfI8PVRQNhye5uLdMdQcsdyAavf636xeAI=; b=k0ZY+NNYE+GteZCRC2eigN0y5AMDruoe8bcV1WuBAYyxODCZigm6Eh+IWHMVv9L5cFbz0eRMh9qNwdikRtE6PZuXIUFufeIaK7WpNvK3suYveruVqNPni9u6B8cEP5wEKWT7SS3ypzocPn3BRZ+AbCyjt96SF2XlV8ZtIl9lzM0= 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+importer=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 1668527919071856.2769054743106; Tue, 15 Nov 2022 07:58:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyn-0005rF-8L; Tue, 15 Nov 2022 10:36: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 1ouxyi-0005nf-38 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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 1ouxyg-0008NE-Kp for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:35:59 -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-467-BWnpH5dGP1OECfgnGdByKg-1; Tue, 15 Nov 2022 10:35:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 403702A5954B; Tue, 15 Nov 2022 15:35:54 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id A5A1D2166B2B; Tue, 15 Nov 2022 15:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526558; 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=8sTZ2tLPTwfI8PVRQNhye5uLdMdQcsdyAavf636xeAI=; b=ANwOSRP8CeC7/E+V8ze52KNSblwBdUeZYykcM+051XVMnZc3JSlwKeRgETpUhK0nIUTgyd g2v27gpWrc4J662k2+s4RVRKg7kZXA/Rc6UWWWKf8NL7nzLr27jVv8uJCejjPbJ1BEWwql DDpDp8mZuy0BcICy27ASpMDlhT3drhE= X-MC-Unique: BWnpH5dGP1OECfgnGdByKg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 10/30] migration: Fix possible infinite loop of ram save process Date: Tue, 15 Nov 2022 16:34:54 +0100 Message-Id: <20221115153514.28003-11-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527920741100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu When starting ram saving procedure (especially at the completion phase), always set last_seen_block to non-NULL to make sure we can always correctly detect the case where "we've migrated all the dirty pages". Then we'll guarantee both last_seen_block and pss.block will be valid always before the loop starts. See the comment in the code for some details. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index bb4f08bfed..c0f5d6d287 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2574,14 +2574,22 @@ static int ram_find_and_save_block(RAMState *rs) return pages; } =20 + /* + * Always keep last_seen_block/last_page valid during this procedure, + * because find_dirty_block() relies on these values (e.g., we compare + * last_seen_block with pss.block to see whether we searched all the + * ramblocks) to detect the completion of migration. Having NULL value + * of last_seen_block can conditionally cause below loop to run foreve= r. + */ + if (!rs->last_seen_block) { + rs->last_seen_block =3D QLIST_FIRST_RCU(&ram_list.blocks); + rs->last_page =3D 0; + } + pss.block =3D rs->last_seen_block; pss.page =3D rs->last_page; pss.complete_round =3D false; =20 - if (!pss.block) { - pss.block =3D QLIST_FIRST_RCU(&ram_list.blocks); - } - do { again =3D true; found =3D get_queued_page(rs, &pss); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527219; cv=none; d=zohomail.com; s=zohoarc; b=VLKrjPrCvPtHNV5xY4McPE+vvmJhN74g3DFSPWFNAmIAkqcf5ML1pOClg4qTsF7RrAc/1p9CyvMBuxf5cGO0Thc+rZtQJfh7uGpOcX/FLR0Qx7tFIUH4lSLCVPvu5dOO2mdS6ETx17OAvX5goo6OtHC7Oy+oWw5mu6vyxYoreFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527219; 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=lv4vZEI7OQUfHArHUOc7UL/dhPGExU7enAwFsaFQkm8=; b=BR28VZX3ZW2RT6bAtYSeJ0RswvFQLu+Iaoe/pQFLULGWvvbDHl2WM7W0wfj/G+vZj86xkhJfw5AZLoZruSkk38MSvDhXssRTDbD+rmAF+HGugJJONJpGa0FHsclgsXyuaFoL7EBMmfFnZaovJC7e9aYcYjGNgLObL70jYNqVedY= 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+importer=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 1668527219556721.2620588650735; Tue, 15 Nov 2022 07:46:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyy-00066v-Ri; Tue, 15 Nov 2022 10:36:16 -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 1ouxyw-00063C-0Z for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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 1ouxys-0008Ov-2N for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:13 -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-379-rRnEhYIOP4ePxd5R-PsBpQ-1; Tue, 15 Nov 2022 10:36:02 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3BB843C0F7EF; Tue, 15 Nov 2022 15:35:57 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8462F2166B2B; Tue, 15 Nov 2022 15:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526569; 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=lv4vZEI7OQUfHArHUOc7UL/dhPGExU7enAwFsaFQkm8=; b=QgO7J6D+/TqzRiWAu3gOgjYGqyu/cTedweN7WlN12jAVlK55Ew9qjqFxKzIHT2LLXEeo3c xe9nlRCYiUgqLyRJozZokbC6NZstegNCzB5q1pJSrnVYfWawqMjDVlxO24kpqluWGaOy+Q pV5A0nQQSoPzWSJ3wVh5I/yWWbpP1MQ= X-MC-Unique: rRnEhYIOP4ePxd5R-PsBpQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 11/30] migration: Fix race on qemu_file_shutdown() Date: Tue, 15 Nov 2022 16:34:55 +0100 Message-Id: <20221115153514.28003-12-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527219813100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu In qemu_file_shutdown(), there's a possible race if with current order of operation. There're two major things to do: (1) Do real shutdown() (e.g. shutdown() syscall on socket) (2) Update qemufile's last_error We must do (2) before (1) otherwise there can be a race condition like: page receiver other thread ------------- ------------ qemu_get_buffer() do shutdown() returns 0 (buffer all zero) (meanwhile we didn't check this retcode) try to detect IO error last_error=3D=3DNULL, IO okay install ALL-ZERO page set last_error --> guest crash! To fix this, we can also check retval of qemu_get_buffer(), but not all APIs can be properly checked and ultimately we still need to go back to qemu_file_get_error(). E.g. qemu_get_byte() doesn't return error. Maybe some day a rework of qemufile API is really needed, but for now keep using qemu_file_get_error() and fix it by not allowing that race condition to happen. Here shutdown() is indeed special because the last_error was emulated. For real -EIO errors it'll always be set when e.g. sendmsg() error triggers so we won't miss those ones, only shutdown() is a bit tricky here. Cc: Daniel P. Berrange Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/qemu-file.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 4f400c2e52..2d5f74ffc2 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -79,6 +79,30 @@ int qemu_file_shutdown(QEMUFile *f) int ret =3D 0; =20 f->shutdown =3D true; + + /* + * We must set qemufile error before the real shutdown(), otherwise + * there can be a race window where we thought IO all went though + * (because last_error=3D=3DNULL) but actually IO has already stopped. + * + * If without correct ordering, the race can happen like this: + * + * page receiver other thread + * ------------- ------------ + * qemu_get_buffer() + * do shutdown() + * returns 0 (buffer all zero) + * (we didn't check this retcode) + * try to detect IO error + * last_error=3D=3DNULL, IO okay + * install ALL-ZERO page + * set last_error + * --> guest crash! + */ + if (!f->last_error) { + qemu_file_set_error(f, -EIO); + } + if (!qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SHUTDOWN)) { return -ENOSYS; @@ -88,9 +112,6 @@ int qemu_file_shutdown(QEMUFile *f) ret =3D -EIO; } =20 - if (!f->last_error) { - qemu_file_set_error(f, -EIO); - } return ret; } =20 --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527527; cv=none; d=zohomail.com; s=zohoarc; b=APP9ZP4etPiib/vWHUI+8DTHcacLzGwn5ojLDU16EeSvaHmrnEsS5/KYzhp5MHL7Fx9hpZ9KQ4MLkiUTjGB6T+ih4lerYmER05EjY8ksgFg5xGL65dJdw32xo4xurr4FaMaNtFou0bz5Hzro0w5f3Ggtxtj/Es+vmnjPrCpH7GM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527527; 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=ZlQ9DFV5GZb35HrLiQSeerG6Q9JfAHXY/TevqMaHCpQ=; b=PrVJeyufd/H7tEgnwSMdnmlbIGdViNEylE7CE/y61mQx6SeNpKf2ysiy1G+PyFVdBcebU3AcyTqP9J+Ze7/NSWR2eAT3ZFhb4f3xfqcmc622UqO4yebsbjNibJrBffxIu9ciMypfMnPZCz1aPhFKhpjYNJqcV5Tyz/D+Ey0dJ84= 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+importer=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 1668527527554253.6067030354012; Tue, 15 Nov 2022 07:52:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyw-00063d-Bc; Tue, 15 Nov 2022 10:36:14 -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 1ouxyu-0005z9-2H for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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 1ouxyo-0008OW-Ji for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:11 -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-77-FJCKyW-yPtCJUOGE1Yj42w-1; Tue, 15 Nov 2022 10:36:02 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30F1D87A9EA; Tue, 15 Nov 2022 15:36:00 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83F7A2166B2C; Tue, 15 Nov 2022 15:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526566; 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=ZlQ9DFV5GZb35HrLiQSeerG6Q9JfAHXY/TevqMaHCpQ=; b=ayLSFjsPw9SUDaEyF5KclRlPUfzRRY/r+Z/f3rf7uXVLVf8xWIhiqd4uMew9EBoeSfmMmK rXOrPQmKuad3bNVkNedIvmlemGew4/VzmC2ZpUmwYquxnVYWkVgSnpBqr05JGw+R67YwfL abl+6qoTAjJnjYWKoDEU0e2w03NtyQ4= X-MC-Unique: FJCKyW-yPtCJUOGE1Yj42w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 12/30] migration: Disallow postcopy preempt to be used with compress Date: Tue, 15 Nov 2022 16:34:56 +0100 Message-Id: <20221115153514.28003-13-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527529619100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu The preempt mode requires the capability to assign channel for each of the page, while the compression logic will currently assign pages to different compress thread/local-channel so potentially they're incompatible. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/migration/migration.c b/migration/migration.c index 406a9e2f72..0bc3fce4b7 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1357,6 +1357,17 @@ static bool migrate_caps_check(bool *cap_list, error_setg(errp, "Postcopy preempt requires postcopy-ram"); return false; } + + /* + * Preempt mode requires urgent pages to be sent in separate + * channel, OTOH compression logic will disorder all pages into + * different compression channels, which is not compatible with the + * preempt assumptions on channel assignments. + */ + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Postcopy preempt not compatible with compres= s"); + return false; + } } =20 return true; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526664; cv=none; d=zohomail.com; s=zohoarc; b=KuO5Y1Wl5cKUZa2kM9nyR3/Ksq/mYEj0C8NBGj74MVqMAqnAUEc/48bSOQAvRl6eRG6pkdHaXO+EIthesWqztVM4MXdtGcT3fJgaZ7dGVcPOu2lw5EL98el+Ow2Syz9Uj7LxLg+NuD7GQudR+ffGp5DFnWGQBR+GbBdVwGZ0Ls8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526664; 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=4j3dbCKGLbNDGAn+c9H7VpwArQIYSq5GKQxPanVzcRI=; b=cT2jV4dGheTPJ4rCR0hXAfbpMo7A8O1UUQLk9TR0XgFCcNGBhLqlF4aU8+zLTG0OHBJD6CGXizJ9ZQsu3VGgg3Lz573w97JlKa73eHwcxDp+Otg/Salek4KFJEuCzrSOLdjOCiV8dBfJMZpUfs+kPWkSXlilY5qjja9gHBdzXXM= 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+importer=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 1668526664744100.61117357490195; Tue, 15 Nov 2022 07:37:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxyv-00063A-W9; Tue, 15 Nov 2022 10:36:14 -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 1ouxyt-0005yt-Pd for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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 1ouxyp-0008Od-SN for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:11 -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-197-my1_ThKENq6pBGElsRbJMQ-1; Tue, 15 Nov 2022 10:36:04 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2DDD5857FB0; Tue, 15 Nov 2022 15:36:03 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7574F2166B2C; Tue, 15 Nov 2022 15:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526567; 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=4j3dbCKGLbNDGAn+c9H7VpwArQIYSq5GKQxPanVzcRI=; b=MV9SJVAGRh+5+poi6m3rXYogzwfGprq8hd09bmT7MOPdKrXd7x89i33ilIeMDI/VwRUJda J1juMOsg6PSZo23mWKEza8WyO5OEzGsUsnP6lKRj6U2zDNSWxfxlbUp91dPuWvRM2NpkHl +zmI/WbiY3Gn8b4v4emq3MNO1aj0gQ4= X-MC-Unique: my1_ThKENq6pBGElsRbJMQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 13/30] migration: Use non-atomic ops for clear log bitmap Date: Tue, 15 Nov 2022 16:34:57 +0100 Message-Id: <20221115153514.28003-14-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526667074100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Since we already have bitmap_mutex to protect either the dirty bitmap or the clear log bitmap, we don't need atomic operations to set/clear/test on the clear log bitmap. Switching all ops from atomic to non-atomic versions, meanwhile touch up the comments to show which lock is in charge. Introduced non-atomic version of bitmap_test_and_clear_atomic(), mostly the same as the atomic version but simplified a few places, e.g. dropped the "old_bits" variable, and also the explicit memory barriers. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- include/exec/ram_addr.h | 11 +++++----- include/exec/ramblock.h | 3 +++ include/qemu/bitmap.h | 1 + util/bitmap.c | 45 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 1500680458..f4fb6a2111 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -42,7 +42,8 @@ static inline long clear_bmap_size(uint64_t pages, uint8_= t shift) } =20 /** - * clear_bmap_set: set clear bitmap for the page range + * clear_bmap_set: set clear bitmap for the page range. Must be with + * bitmap_mutex held. * * @rb: the ramblock to operate on * @start: the start page number @@ -55,12 +56,12 @@ static inline void clear_bmap_set(RAMBlock *rb, uint64_= t start, { uint8_t shift =3D rb->clear_bmap_shift; =20 - bitmap_set_atomic(rb->clear_bmap, start >> shift, - clear_bmap_size(npages, shift)); + bitmap_set(rb->clear_bmap, start >> shift, clear_bmap_size(npages, shi= ft)); } =20 /** - * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set + * clear_bmap_test_and_clear: test clear bitmap for the page, clear if set. + * Must be with bitmap_mutex held. * * @rb: the ramblock to operate on * @page: the page number to check @@ -71,7 +72,7 @@ static inline bool clear_bmap_test_and_clear(RAMBlock *rb= , uint64_t page) { uint8_t shift =3D rb->clear_bmap_shift; =20 - return bitmap_test_and_clear_atomic(rb->clear_bmap, page >> shift, 1); + return bitmap_test_and_clear(rb->clear_bmap, page >> shift, 1); } =20 static inline bool offset_in_ramblock(RAMBlock *b, ram_addr_t offset) diff --git a/include/exec/ramblock.h b/include/exec/ramblock.h index 6cbedf9e0c..adc03df59c 100644 --- a/include/exec/ramblock.h +++ b/include/exec/ramblock.h @@ -53,6 +53,9 @@ struct RAMBlock { * and split clearing of dirty bitmap on the remote node (e.g., * KVM). The bitmap will be set only when doing global sync. * + * It is only used during src side of ram migration, and it is + * protected by the global ram_state.bitmap_mutex. + * * NOTE: this bitmap is different comparing to the other bitmaps * in that one bit can represent multiple guest pages (which is * decided by the `clear_bmap_shift' variable below). On diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 82a1d2f41f..3ccb00865f 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -253,6 +253,7 @@ void bitmap_set(unsigned long *map, long i, long len); void bitmap_set_atomic(unsigned long *map, long i, long len); void bitmap_clear(unsigned long *map, long start, long nr); bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr); +bool bitmap_test_and_clear(unsigned long *map, long start, long nr); void bitmap_copy_and_clear_atomic(unsigned long *dst, unsigned long *src, long nr); unsigned long bitmap_find_next_zero_area(unsigned long *map, diff --git a/util/bitmap.c b/util/bitmap.c index f81d8057a7..8d12e90a5a 100644 --- a/util/bitmap.c +++ b/util/bitmap.c @@ -240,6 +240,51 @@ void bitmap_clear(unsigned long *map, long start, long= nr) } } =20 +bool bitmap_test_and_clear(unsigned long *map, long start, long nr) +{ + unsigned long *p =3D map + BIT_WORD(start); + const long size =3D start + nr; + int bits_to_clear =3D BITS_PER_LONG - (start % BITS_PER_LONG); + unsigned long mask_to_clear =3D BITMAP_FIRST_WORD_MASK(start); + bool dirty =3D false; + + assert(start >=3D 0 && nr >=3D 0); + + /* First word */ + if (nr - bits_to_clear > 0) { + if ((*p) & mask_to_clear) { + dirty =3D true; + } + *p &=3D ~mask_to_clear; + nr -=3D bits_to_clear; + bits_to_clear =3D BITS_PER_LONG; + p++; + } + + /* Full words */ + if (bits_to_clear =3D=3D BITS_PER_LONG) { + while (nr >=3D BITS_PER_LONG) { + if (*p) { + dirty =3D true; + *p =3D 0; + } + nr -=3D BITS_PER_LONG; + p++; + } + } + + /* Last word */ + if (nr) { + mask_to_clear &=3D BITMAP_LAST_WORD_MASK(size); + if ((*p) & mask_to_clear) { + dirty =3D true; + } + *p &=3D ~mask_to_clear; + } + + return dirty; +} + bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr) { unsigned long *p =3D map + BIT_WORD(start); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527044; cv=none; d=zohomail.com; s=zohoarc; b=NLLXZM+5Sb5KA8d1wLkB23wOjpQty/RhKErorsyBVCuNvoqneMhgYddv+LzFTizFMJtF6Dlphr2DD6sXKiivR/70eyC6djgejrE64KYfUM4QwhawNReylJQTyYtV/NOdA6IYNWB7g43BFrSJnd4dMHwvf3qHUzP0hvafwCkGavk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527044; 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=KYeIQe/j3B37yyq4ayWjo2p+YUwHJONfvHLwiEzscgk=; b=oB6sDjhMgH9qhYu2ArBHIOnRg1tq9Ra67ScobQ6VevH2rdkUqOrwB9T/ojbURmNIz1T80xXOXe2Kx8bcwgdW+k/7wMi0XbREeTwWim3itVs46jkFrHvx6qf72a8IIbUMThQjxS6G/xr68xAYHOy2krhEL41vkPAhLnUv3NQL3jQ= 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+importer=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 1668527044733850.0532944761331; Tue, 15 Nov 2022 07:44:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxz0-000684-A2; Tue, 15 Nov 2022 10:36:18 -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 1ouxyw-00063F-1O for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:14 -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 1ouxys-0008Ox-2i for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:13 -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-608-ldi5aoEdNZG6nfzwo5Frpg-1; Tue, 15 Nov 2022 10:36:06 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2877A1C075B6; Tue, 15 Nov 2022 15:36:06 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 739082166B2C; Tue, 15 Nov 2022 15:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526569; 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=KYeIQe/j3B37yyq4ayWjo2p+YUwHJONfvHLwiEzscgk=; b=f2OLUZQ6XrzNGC8mBaX1p7W215E072yYuv2xzbmFwVAcShmlbUyaArCO6LBatH1FlPxtQ1 BJOU+KY2Fm27jvGpm9OXj7fDdBCbf1XCQ/Lg9wQfIbhd7z9wM2Ek3Ppo/ocZDY1TlCWEKW CcSVLUGzhsmvfni7L/kUiptficOlNEI= X-MC-Unique: ldi5aoEdNZG6nfzwo5Frpg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 14/30] migration: Disable multifd explicitly with compression Date: Tue, 15 Nov 2022 16:34:58 +0100 Message-Id: <20221115153514.28003-15-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527045115100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Multifd thread model does not work for compression, explicitly disable it. Note that previuosly even we can enable both of them, nothing will go wrong, because the compression code has higher priority so multifd feature will just be ignored. Now we'll fail even earlier at config time so the user should be aware of the consequence better. Note that there can be a slight chance of breaking existing users, but let's assume they're not majority and not serious users, or they should have found that multifd is not working already. With that, we can safely drop the check in ram_save_target_page() for using multifd, because when multifd=3Don then compression=3Doff, then the removed check on save_page_use_compression() will also always return false too. Signed-off-by: Peter Xu Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 7 +++++++ migration/ram.c | 11 +++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 0bc3fce4b7..9fbed8819a 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1370,6 +1370,13 @@ static bool migrate_caps_check(bool *cap_list, } } =20 + if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) { + if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) { + error_setg(errp, "Multifd is not compatible with compress"); + return false; + } + } + return true; } =20 diff --git a/migration/ram.c b/migration/ram.c index c0f5d6d287..2fcce796d0 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2333,13 +2333,12 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) } =20 /* - * Do not use multifd for: - * 1. Compression as the first page in the new block should be posted = out - * before sending the compressed page - * 2. In postcopy as one whole host page should be placed + * Do not use multifd in postcopy as one whole host page should be + * placed. Meanwhile postcopy requires atomic update of pages, so even + * if host page size =3D=3D guest page size the dest guest during run = may + * still see partially copied pages which is data corruption. */ - if (!save_page_use_compression(rs) && migrate_use_multifd() - && !migration_in_postcopy()) { + if (migrate_use_multifd() && !migration_in_postcopy()) { return ram_save_multifd_page(rs, block, offset); } =20 --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526689; cv=none; d=zohomail.com; s=zohoarc; b=Bf/wpKEdPLpUXRtZZ1Z0hQ4Kc+SJev9i0K5bAK7QWd9srQQLi2avQAkEra6hN1uwjn0MYrgCgz5f6hJYzVcQJGfdzfH+0eZeNJo8GsyfvgCcWEWUj+95FM5NvlsxnG+ZL32hwWAb3r1EHuuzKdWn/252VPDHT3pPPmXP8R7+9Zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526689; 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=dg3mCFE8uw/wfOpkRNh1WTdMqbNPgtOyxMHit2mecd8=; b=iKoAutnrcexwncGAJ2wX58sB+d5lGH+49XxXGwXrh4s5DGMseuAGHow2gKCeKDgnFde5eHi01xth0dcCBmfdBiEzbKSriGTDSMvrSnXxS4tZbSdF3kBp9UklNau9fpJpWT/NH0ljPXNOwSJZdEZuyR3/P+wlh4qWBEJPYUfrc/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+importer=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 1668526689796257.29734230638826; Tue, 15 Nov 2022 07:38:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxz2-00069s-7r; Tue, 15 Nov 2022 10:36: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 1ouxyx-00065y-Tt for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:15 -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 1ouxyv-0008QB-IJ for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:15 -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-605-F69ZRHEYMJOFk_vBfqoufA-1; Tue, 15 Nov 2022 10:36:09 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 00E0586F12E; Tue, 15 Nov 2022 15:36:09 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 729BD2166B2B; Tue, 15 Nov 2022 15:36:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526573; 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=dg3mCFE8uw/wfOpkRNh1WTdMqbNPgtOyxMHit2mecd8=; b=L1jqUVTXyBU7buwV60L1R7KfLvXP94r3OEMjTYUkj7ZvtKOOQzm26Mhm5BS0/AqsF0uZ9n gpUn95QYfqEQJIANDAz4En00su5hYxTLpRDCiE2n1DAoWYIbU78ADjVKLDH/29VLKIZlNL hO0IFie5XTV5yRgxL4t6rYxfedOiAo4= X-MC-Unique: F69ZRHEYMJOFk_vBfqoufA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 15/30] migration: Take bitmap mutex when completing ram migration Date: Tue, 15 Nov 2022 16:34:59 +0100 Message-Id: <20221115153514.28003-16-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526691244100011 Content-Type: text/plain; charset="utf-8" From: Peter Xu Any call to ram_find_and_save_block() needs to take the bitmap mutex. We used to not take it for most of ram_save_complete() because we thought we're the only one left using the bitmap, but it's not true after the preempt full patchset applied, since the return path can be taking it too. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 2fcce796d0..96fa521813 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3434,6 +3434,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) /* try transferring iterative blocks of memory */ =20 /* flush all remaining blocks regardless of rate limiting */ + qemu_mutex_lock(&rs->bitmap_mutex); while (true) { int pages; =20 @@ -3447,6 +3448,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) break; } } + qemu_mutex_unlock(&rs->bitmap_mutex); =20 flush_compressed_data(rs); ram_control_after_iterate(f, RAM_CONTROL_FINISH); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527667; cv=none; d=zohomail.com; s=zohoarc; b=TZcAk87OycoSbpVyF+SgLZ/iWJjUzbDUFHWpg0A5LNqr0vEzFbwiAlRMnoyEoF3z1Bz2mRCLWaU45uV6Eg5FoBXalvWX2SeMaW+76Wys83b3qGeCWTZfF99yr8gZA6/mzOaDIi5ohYjDqA+w+l9s7zocjT6hCClaAYNiLlv9xzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527667; 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=0ib/Nn4e1ptwb4ggHnzmqlth4juAjFEriRfMckzYNJo=; b=j71L4VAcmdAS+rH9nxN5U5J+S2qYJ60sCSlXp6hFrebFCRo4+Imnr4zSnq6/Aq6ubYdVFmP7NoejMcJoUt+5hj9MZyMtlKgdRgRgho78FlirXJT0Vl3UOc9NWntBMbPanh7NMv/xeEwz7xxIZSvc2KfT+syZGXQ1WyrAt6pVzMM= 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+importer=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 1668527667467708.4053617443693; Tue, 15 Nov 2022 07:54:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzP-0006KE-O6; Tue, 15 Nov 2022 10:36:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ouxz0-00068Q-9R for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:18 -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 1ouxyy-0008RK-5f for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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-507-ZLEDA2CWMuajf1_W3dp2cw-1; Tue, 15 Nov 2022 10:36:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD1B4811E75; Tue, 15 Nov 2022 15:36:11 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44C272166B2B; Tue, 15 Nov 2022 15:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526575; 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=0ib/Nn4e1ptwb4ggHnzmqlth4juAjFEriRfMckzYNJo=; b=SdmTDHaaSdRPjFvYTauvhn9gfxMeKil0XFN17SEAfokSf+8adGmAaexuLUHlSA3T0sZXox f2yl8taby6jykpMlkmVF1HJl6pKlGeW/NrtEa4bgdeU2lQ6rWM2kuI7wSTKc/1PUpNmCeP vU1wK7AKHTvYs0Z0+CShEjbJj2LYLm0= X-MC-Unique: ZLEDA2CWMuajf1_W3dp2cw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 16/30] migration: Add postcopy_preempt_active() Date: Tue, 15 Nov 2022 16:35:00 +0100 Message-Id: <20221115153514.28003-17-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527669482100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Add the helper to show that postcopy preempt enabled, meanwhile active. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 96fa521813..52c851eb56 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -190,6 +190,11 @@ out: return ret; } =20 +static bool postcopy_preempt_active(void) +{ + return migrate_postcopy_preempt() && migration_in_postcopy(); +} + bool ramblock_is_ignored(RAMBlock *block) { return !qemu_ram_is_migratable(block) || @@ -2461,7 +2466,7 @@ static void postcopy_preempt_choose_channel(RAMState = *rs, PageSearchStatus *pss) /* We need to make sure rs->f always points to the default channel elsewhe= re */ static void postcopy_preempt_reset_channel(RAMState *rs) { - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; rs->f =3D migrate_get_current()->to_dst_file; trace_postcopy_preempt_reset_channel(); @@ -2499,7 +2504,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) return 0; } =20 - if (migrate_postcopy_preempt() && migration_in_postcopy()) { + if (postcopy_preempt_active()) { postcopy_preempt_choose_channel(rs, pss); } =20 --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526776; cv=none; d=zohomail.com; s=zohoarc; b=jDDq0whxeUnCZR2feYfAQh3NqiWu2dTzFk6nzJUjRGTlIfuG7r2a2x4q9+yFeuzF1QThM3DZzEmmEv9pojcsb6QLBn+aw33QQ6P1/NTz02NC6fTo5jMZPjJAcMr/MlexlFZhFBZibeNo3dfn2OJjchEr/UjEwaNU8+H0Ug0HfXE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526776; 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=UVeEMvUw7lDrkeTwQscCKF/k8ynoE0BxYgJFbBO3SpM=; b=F1qfwtUWePbvzesBvKQs8se6ixzG56EteyewhDfGoQxIE9NhHsOnw3JrleavQC6nZVxt6UrOfkINKMMyrnMDIBymZEeEUKpuKG0Sxg50Cg5myRnuV874s2cyV/6OGoPvgDP1ZM9B+igtVdq6chUqSOlYI5dxMGTDiG7VwAZtR5o= 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+importer=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 1668526776500890.1840083747037; Tue, 15 Nov 2022 07:39:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzQ-0006Mx-Tx; Tue, 15 Nov 2022 10:36: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 1ouxz5-0006Am-Kd for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:29 -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 1ouxz4-0008SR-2G for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:23 -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-393-oycDPABiP4mDgxWRs3dKlg-1; Tue, 15 Nov 2022 10:36:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB495185A7A3; Tue, 15 Nov 2022 15:36:15 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D8702166B2B; Tue, 15 Nov 2022 15:36:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526581; 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=UVeEMvUw7lDrkeTwQscCKF/k8ynoE0BxYgJFbBO3SpM=; b=RPMMlP/AbdCx4rMVZFi+RbeG2EmBfeFedBx/nChoymGQRiM2OgHTwN9nVZb0a7mNvzjvFy Vp+x4+WrhJ9rLHuHPadA4p0laUc3dD9iJ4/bYmz1LD2tyGFFW1rEE5rhCHFP507uJEAR7A +uYWmrOQpK4IL2gtb1g0n0giTaQI134= X-MC-Unique: oycDPABiP4mDgxWRs3dKlg-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 17/30] migration: Cleanup xbzrle zero page cache update logic Date: Tue, 15 Nov 2022 16:35:01 +0100 Message-Id: <20221115153514.28003-18-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526777610100002 Content-Type: text/plain; charset="utf-8" From: Peter Xu The major change is to replace "!save_page_use_compression()" with "xbzrle_enabled" to make it clear. Reasonings: (1) When compression enabled, "!save_page_use_compression()" is exactly the same as checking "xbzrle_enabled". (2) When compression disabled, "!save_page_use_compression()" always return true. We used to try calling the xbzrle code, but after this change we won't, and we shouldn't need to. Since at it, drop the xbzrle_enabled check in xbzrle_cache_zero_page() because with this change it's not needed anymore. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 52c851eb56..9ded381e0a 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -769,10 +769,6 @@ void mig_throttle_counter_reset(void) */ static void xbzrle_cache_zero_page(RAMState *rs, ram_addr_t current_addr) { - if (!rs->xbzrle_enabled) { - return; - } - /* We don't care if this fails to allocate a new cache page * as long as it updated an old one */ cache_insert(XBZRLE.cache, current_addr, XBZRLE.zero_target_page, @@ -2329,7 +2325,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale */ - if (!save_page_use_compression(rs)) { + if (rs->xbzrle_enabled) { XBZRLE_cache_lock(); xbzrle_cache_zero_page(rs, block->offset + offset); XBZRLE_cache_unlock(); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526685; cv=none; d=zohomail.com; s=zohoarc; b=S81/xN4dbc4dHhN6G2JaP2CHfghkYmIC1GZhLnprfGskt4uiAZsU+XzGVHsSdrpTEJjC6ul0x5+e9p4jSHLVn454SxASGhw+KIrwwK8nma/EotPDwRxJ0rWdmKZud+7tCcLrmjtPkYv/MeDnWVz7sDvcePa4gWjYZM24pNiB7aM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526685; 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=zZyCXKLYLrpw6dr0uW+L3vfIKuXZhrWxjl11Z1i2PBY=; b=BqJwFQrOUGp1JkmibgDqnH2VugnoffLPN97RJ9aupBqki7+5Axev8WAjaF+U0xt5Z7w62QIRSHTQYitNNNd1/hq39gwketyQojPqDa03t8R7oOSz5VQEVeg/wDPjEK6U/kvrPhUlJTOE21W+l0XqnRVb2R+51mResszc20xGi9g= 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+importer=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 1668526685662164.747470223719; Tue, 15 Nov 2022 07:38:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzT-0006QB-3e; Tue, 15 Nov 2022 10:36:47 -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 1ouxz5-0006Ag-3u for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:29 -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 1ouxz3-0008SJ-9w for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:22 -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-272-G9BUEXc9NGGTCPDsoz-xdQ-1; Tue, 15 Nov 2022 10:36:19 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CC9313C0F7F0; Tue, 15 Nov 2022 15:36:18 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C2C22166B2B; Tue, 15 Nov 2022 15:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526580; 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=zZyCXKLYLrpw6dr0uW+L3vfIKuXZhrWxjl11Z1i2PBY=; b=QWiOvllhy8QxZOgOE+kNO59ISczzhUsYWuADDEWtKgYVVvxWzvKiVYnyJxjRHhaWV0NM/s ALUv86D+iux/T1jWUYZz33tNRcRWNvowrnMxSiESmDd007ZLObuacWghe0iIut/AF5NYp7 GD0R7CHX4d1eAcVXaMy4UFr6gqc01VY= X-MC-Unique: G9BUEXc9NGGTCPDsoz-xdQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 18/30] migration: Trivial cleanup save_page_header() on same block check Date: Tue, 15 Nov 2022 16:35:02 +0100 Message-Id: <20221115153514.28003-19-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526687214100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu The 2nd check on RAM_SAVE_FLAG_CONTINUE is a bit redundant. Use a boolean to be clearer. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela 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 9ded381e0a..42b6a543bd 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -689,14 +689,15 @@ static size_t save_page_header(RAMState *rs, QEMUFile= *f, RAMBlock *block, ram_addr_t offset) { size_t size, len; + bool same_block =3D (block =3D=3D rs->last_sent_block); =20 - if (block =3D=3D rs->last_sent_block) { + if (same_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; } qemu_put_be64(f, offset); size =3D 8; =20 - if (!(offset & RAM_SAVE_FLAG_CONTINUE)) { + if (!same_block) { len =3D strlen(block->idstr); qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526746; cv=none; d=zohomail.com; s=zohoarc; b=YhsMPN7KUXnMKPH7s7JOu3UNlFVGhXthPrbaOgoN7V0Yxs5h6h7ma1RN98nFQlMHuZxJAK1MawqKq/+UnO+FtVAUkjL1KRgpWrhC72Nh2XeNbhjQQQTfinkP7FPTNkJQIJvup4FbKYZUIJvZN3YhHIjyfRPGxLh54SB/zAA4Nfw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526746; 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=FPDQgKzIwXCHvxX4wKZA3637zJhXFXMBJzVGXhQpw0Q=; b=m6GnMWmzYAGU/eMyhby+F8Nh5rexXscrptnmUMPhohpooKUgMWqR3xFejWK8GZkT44ztQuPgk9DtpX3gIdX+TMaiNAoarDhQ3FATynY2xgG5NXoIR0AQXVGGhzz5ZXcZeTWHdkM0xLsW4yBEmyKnRMotdqv76vzgE0qM3X/IZTs= 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+importer=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 166852674631853.950807758321844; Tue, 15 Nov 2022 07:39:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzS-0006P5-Dj; Tue, 15 Nov 2022 10:36:46 -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 1ouxzC-0006BW-5E for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:39 -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 1ouxz9-0008TU-I9 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:29 -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-55-B3SHgFfaP-iPAT7e-o6wXw-1; Tue, 15 Nov 2022 10:36:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C49D387A9FB; Tue, 15 Nov 2022 15:36:21 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209FA2166B2B; Tue, 15 Nov 2022 15:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526585; 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=FPDQgKzIwXCHvxX4wKZA3637zJhXFXMBJzVGXhQpw0Q=; b=aBljFzGqXdv0P8iEAu0cra3+Bd0G2iivQ23mS3wJcaxrG/OJoiPM/bx+3mJ1oHyneg0uWN sZHO4dxqTm7jvpyxEAJSggJBh2LldwKzilfWz222KMfyZmbjE45QYj4yNirVcfVTSnvciX SpGFGsUllCoPCnhjEPU8EpiJ9J1aQJM= X-MC-Unique: B3SHgFfaP-iPAT7e-o6wXw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 19/30] migration: Remove RAMState.f references in compression code Date: Tue, 15 Nov 2022 16:35:03 +0100 Message-Id: <20221115153514.28003-20-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526747503100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Removing referencing to RAMState.f in compress_page_with_multi_thread() and flush_compressed_data(). Compression code by default isn't compatible with having >1 channels (or it won't currently know which channel to flush the compressed data), so to make it simple we always flush on the default to_dst_file port until someone wants to add >1 ports support, as rs->f right now can really change (after postcopy preempt is introduced). There should be no functional change at all after patch applied, since as long as rs->f referenced in compression code, it must be to_dst_file. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Signed-off-by: Juan Quintela --- migration/ram.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 42b6a543bd..ebc5664dcc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1489,6 +1489,7 @@ static bool save_page_use_compression(RAMState *rs); =20 static void flush_compressed_data(RAMState *rs) { + MigrationState *ms =3D migrate_get_current(); int idx, len, thread_count; =20 if (!save_page_use_compression(rs)) { @@ -1507,7 +1508,7 @@ static void flush_compressed_data(RAMState *rs) for (idx =3D 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); + len =3D qemu_put_qemu_file(ms->to_dst_file, comp_param[idx].fi= le); /* * it's safe to fetch zero_page without holding comp_done_lock * as there is no further request submitted to the thread, @@ -1526,11 +1527,11 @@ static inline void set_compress_params(CompressPara= m *param, RAMBlock *block, param->offset =3D offset; } =20 -static int compress_page_with_multi_thread(RAMState *rs, RAMBlock *block, - ram_addr_t offset) +static int compress_page_with_multi_thread(RAMBlock *block, ram_addr_t off= set) { int idx, thread_count, bytes_xmit =3D -1, pages =3D -1; bool wait =3D migrate_compress_wait_thread(); + MigrationState *ms =3D migrate_get_current(); =20 thread_count =3D migrate_compress_threads(); qemu_mutex_lock(&comp_done_lock); @@ -1538,7 +1539,8 @@ retry: for (idx =3D 0; idx < thread_count; idx++) { if (comp_param[idx].done) { comp_param[idx].done =3D false; - bytes_xmit =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); + bytes_xmit =3D qemu_put_qemu_file(ms->to_dst_file, + comp_param[idx].file); qemu_mutex_lock(&comp_param[idx].mutex); set_compress_params(&comp_param[idx], block, offset); qemu_cond_signal(&comp_param[idx].cond); @@ -2291,7 +2293,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock= *block, ram_addr_t offset) return false; } =20 - if (compress_page_with_multi_thread(rs, block, offset) > 0) { + if (compress_page_with_multi_thread(block, offset) > 0) { return true; } =20 --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527236; cv=none; d=zohomail.com; s=zohoarc; b=A20nrYWs4rAQIchdBTCnIpAmg6K2sGZ1OrDtbcB5Jy+Nb9xmy/J8gQgW0FK9w7IHT8yrP0GkrNubg60pyV/TE1AlEBvQ35SCUn0TebLbTDURl0Voaeu9wIXpu6tn55hNkU0wvB3d6Bg2bcYozU/BGIcEBaX11N1SgZMVhwytCCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527236; 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=W4gYdFB8JnzXjKUrplhGzUi3gnS4DOZf/usoccN+O3g=; b=GSLpaDXeeFwg2Qed9pfIOEBKPsGSYT/uL0W/6VoT4U69qVSMZTRjYx7BpW3l8GcQ2BySJYBZqHgRK+CC8qm8i2QpV/OEYuFrhOpXU/0d1A6kZjNdvNi8ZpQ1G8O70tIrJrwUNCwg1iLPN7uOuNbrZMd/B2vNR0NG1RQkhpdGjp4= 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+importer=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 1668527236655341.0194373808516; Tue, 15 Nov 2022 07:47:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzU-0006Tu-Rp; Tue, 15 Nov 2022 10:36:48 -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 1ouxzC-0006BZ-O9 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:39 -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 1ouxzB-0008Tt-7F for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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-557-0JuTS73pNOiKF-7wBFu88w-1; Tue, 15 Nov 2022 10:36:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD3A12A5956D; Tue, 15 Nov 2022 15:36:24 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A49F2166B2B; Tue, 15 Nov 2022 15:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526588; 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=W4gYdFB8JnzXjKUrplhGzUi3gnS4DOZf/usoccN+O3g=; b=GmkzCMCFi3DWxA+7LvIClZa0HTaBsnAR2annZ6mByMOmiYRsSMDJB/+6Oaj0zg2FRlIm4V 19xs0gz403mVqAnL+cqV5XiexMCzieb+U4GVKLl1r9PRzoIgRGKkASoTdmYJZpqp5CYbCJ d6VkP5SI3qLoMUhNF5G5HBxLePf3gaU= X-MC-Unique: 0JuTS73pNOiKF-7wBFu88w-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 20/30] migration: Yield bitmap_mutex properly when sending/sleeping Date: Tue, 15 Nov 2022 16:35:04 +0100 Message-Id: <20221115153514.28003-21-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527237994100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Don't take the bitmap mutex when sending pages, or when being throttled by migration_rate_limit() (which is a bit tricky to call it here in ram code, but seems still helpful). It prepares for the possibility of concurrently sending pages in >1 threads using the function ram_save_host_page() because all threads may need the bitmap_mutex to operate on bitmaps, so that either sendmsg() or any kind of qemu_sem_wait() blocking for one thread will not block the other from progressing. Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index ebc5664dcc..6428138194 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2480,9 +2480,14 @@ static void postcopy_preempt_reset_channel(RAMState = *rs) * a host page in which case the remainder of the hostpage is sent. * Only dirty target pages are sent. Note that the host page size may * be a huge page for this block. + * * The saving stops at the boundary of the used_length of the block * if the RAMBlock isn't a multiple of the host page size. * + * The caller must be with ram_state.bitmap_mutex held to call this + * function. Note that this function can temporarily release the lock, but + * when the function is returned it'll make sure the lock is still held. + * * Returns the number of pages written or negative on error * * @rs: current RAM state @@ -2490,6 +2495,7 @@ static void postcopy_preempt_reset_channel(RAMState *= rs) */ static int ram_save_host_page(RAMState *rs, PageSearchStatus *pss) { + bool page_dirty, preempt_active =3D postcopy_preempt_active(); int tmppages, pages =3D 0; size_t pagesize_bits =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; @@ -2513,22 +2519,40 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss) break; } =20 + page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); + /* Check the pages is dirty and if it is send it */ - if (migration_bitmap_clear_dirty(rs, pss->block, pss->page)) { + if (page_dirty) { + /* + * Properly yield the lock only in postcopy preempt mode + * because both migration thread and rp-return thread can + * operate on the bitmaps. + */ + if (preempt_active) { + qemu_mutex_unlock(&rs->bitmap_mutex); + } tmppages =3D ram_save_target_page(rs, pss); - if (tmppages < 0) { - return tmppages; + if (tmppages >=3D 0) { + pages +=3D tmppages; + /* + * Allow rate limiting to happen in the middle of huge pag= es if + * something is sent in the current iteration. + */ + if (pagesize_bits > 1 && tmppages > 0) { + migration_rate_limit(); + } } - - pages +=3D tmppages; - /* - * Allow rate limiting to happen in the middle of huge pages if - * something is sent in the current iteration. - */ - if (pagesize_bits > 1 && tmppages > 0) { - migration_rate_limit(); + if (preempt_active) { + qemu_mutex_lock(&rs->bitmap_mutex); } + } else { + tmppages =3D 0; + } + + if (tmppages < 0) { + return tmppages; } + pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->pag= e); } while ((pss->page < hostpage_boundary) && offset_in_ramblock(pss->block, --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527226; cv=none; d=zohomail.com; s=zohoarc; b=VfzfKc/GGMOBVKJI3j38/YfYxyGceqlbavLGF2pTEVEbwAmMGdsTfewbFs+jLPutJc5XN/5e4EaN7uI8Gj4uqz54NKb7O7fNl0vksGVVIekBNNtEDo6Cn/bOT0YSfgz6YhWjfNeKIHaAYkvl+YhelUnRmyky9yd2cyQNNUCUhkw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527226; 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=7NP+YAzVniqZo6cfLnT/BIbA/QWmFaZDBpD0elMMoGc=; b=aQ4wo3pRxsR11Rucyt3SE1Y8U6s/6OrKCc/pGloWhKNf0CXtC/XLcLkJhaBO2pXeHpjlc2Ijzw+A4tanj/t1BkSl9Srr555ccNGUXwL+2waTPC4iQjw887P9TQdFI8hxrpQ+SgibACOlsWEu8iOmT/AmoZPaZm8Zt7SoG/Pfm/I= 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+importer=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 16685272269401013.5413051589976; Tue, 15 Nov 2022 07:47:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzT-0006QJ-8i; Tue, 15 Nov 2022 10:36:47 -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 1ouxzF-0006C2-KM for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:39 -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 1ouxzD-0008WE-TV for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:33 -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-140-KxQYppSBO9umZBMtH-LJCw-1; Tue, 15 Nov 2022 10:36:28 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C014F2A5954D; Tue, 15 Nov 2022 15:36:27 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 121172166B2B; Tue, 15 Nov 2022 15:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526591; 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=7NP+YAzVniqZo6cfLnT/BIbA/QWmFaZDBpD0elMMoGc=; b=eImN/0/sqYCxhwCIVRyWfFwaR6ROMD3zhQBsrZCnzeG/6XjzTQNs7vzoyEw4Y/qRkNkFL/ 0eryyPTUGr68QvGrASi2IVNomyt7jgfT0mM+ifRQkaxQXdRctOfRDUQMz6ARcx+ksqRkaP Gqvyagea2FHuitsYOaqFcEa9wYMdHsg= X-MC-Unique: KxQYppSBO9umZBMtH-LJCw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 21/30] migration: Use atomic ops properly for page accountings Date: Tue, 15 Nov 2022 16:35:05 +0100 Message-Id: <20221115153514.28003-22-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527227956100005 Content-Type: text/plain; charset="utf-8" From: Peter Xu To prepare for thread-safety on page accountings, at least below counters need to be accessed only atomically, they are: ram_counters.transferred ram_counters.duplicate ram_counters.normal ram_counters.postcopy_bytes There are a lot of other counters but they won't be accessed outside migration thread, then they're still safe to be accessed without atomic ops. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.h | 20 ++++++++++++++++++++ migration/migration.c | 10 +++++----- migration/multifd.c | 4 ++-- migration/ram.c | 40 ++++++++++++++++++++++++---------------- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/migration/ram.h b/migration/ram.h index 038d52f49f..81cbb0947c 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -32,7 +32,27 @@ #include "qapi/qapi-types-migration.h" #include "exec/cpu-common.h" #include "io/channel.h" +#include "qemu/stats64.h" =20 +/* + * These are the migration statistic counters that need to be updated using + * atomic ops (can be accessed by more than one thread). Here since we + * cannot modify MigrationStats directly to use Stat64 as it was defined in + * the QAPI scheme, we define an internal structure to hold them, and we + * propagate the real values when QMP queries happen. + * + * IOW, the corresponding fields within ram_counters on these specific + * fields will be always zero and not being used at all; they're just + * placeholders to make it QAPI-compatible. + */ +typedef struct { + Stat64 transferred; + Stat64 duplicate; + Stat64 normal; + Stat64 postcopy_bytes; +} MigrationAtomicStats; + +extern MigrationAtomicStats ram_atomic_counters; extern MigrationStats ram_counters; extern XBZRLECacheStats xbzrle_counters; extern CompressionStats compression_counters; diff --git a/migration/migration.c b/migration/migration.c index 9fbed8819a..1f95877fb4 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1069,13 +1069,13 @@ static void populate_ram_info(MigrationInfo *info, = MigrationState *s) =20 info->has_ram =3D true; info->ram =3D g_malloc0(sizeof(*info->ram)); - info->ram->transferred =3D ram_counters.transferred; + info->ram->transferred =3D stat64_get(&ram_atomic_counters.transferred= ); info->ram->total =3D ram_bytes_total(); - info->ram->duplicate =3D ram_counters.duplicate; + info->ram->duplicate =3D stat64_get(&ram_atomic_counters.duplicate); /* legacy value. It is not used anymore */ info->ram->skipped =3D 0; - info->ram->normal =3D ram_counters.normal; - info->ram->normal_bytes =3D ram_counters.normal * page_size; + info->ram->normal =3D stat64_get(&ram_atomic_counters.normal); + info->ram->normal_bytes =3D info->ram->normal * page_size; info->ram->mbps =3D s->mbps; info->ram->dirty_sync_count =3D ram_counters.dirty_sync_count; info->ram->dirty_sync_missed_zero_copy =3D @@ -1086,7 +1086,7 @@ static void populate_ram_info(MigrationInfo *info, Mi= grationState *s) info->ram->pages_per_second =3D s->pages_per_second; info->ram->precopy_bytes =3D ram_counters.precopy_bytes; info->ram->downtime_bytes =3D ram_counters.downtime_bytes; - info->ram->postcopy_bytes =3D ram_counters.postcopy_bytes; + info->ram->postcopy_bytes =3D stat64_get(&ram_atomic_counters.postcopy= _bytes); =20 if (migrate_use_xbzrle()) { info->has_xbzrle_cache =3D true; diff --git a/migration/multifd.c b/migration/multifd.c index c40d98ad5c..7d3aec9a52 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -432,7 +432,7 @@ static int multifd_send_pages(QEMUFile *f) transferred =3D ((uint64_t) pages->num) * p->page_size + p->packet_len; qemu_file_acct_rate_limit(f, transferred); ram_counters.multifd_bytes +=3D transferred; - ram_counters.transferred +=3D transferred; + stat64_add(&ram_atomic_counters.transferred, transferred); qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 @@ -624,7 +624,7 @@ int multifd_send_sync_main(QEMUFile *f) p->pending_job++; qemu_file_acct_rate_limit(f, p->packet_len); ram_counters.multifd_bytes +=3D p->packet_len; - ram_counters.transferred +=3D p->packet_len; + stat64_add(&ram_atomic_counters.transferred, p->packet_len); qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); =20 diff --git a/migration/ram.c b/migration/ram.c index 6428138194..25fd3cf7dc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -453,18 +453,25 @@ uint64_t ram_bytes_remaining(void) 0; } =20 +/* + * NOTE: not all stats in ram_counters are used in reality. See comments + * for struct MigrationAtomicStats. The ultimate result of ram migration + * counters will be a merged version with both ram_counters and the atomic + * fields in ram_atomic_counters. + */ MigrationStats ram_counters; +MigrationAtomicStats ram_atomic_counters; =20 void ram_transferred_add(uint64_t bytes) { if (runstate_is_running()) { ram_counters.precopy_bytes +=3D bytes; } else if (migration_in_postcopy()) { - ram_counters.postcopy_bytes +=3D bytes; + stat64_add(&ram_atomic_counters.postcopy_bytes, bytes); } else { ram_counters.downtime_bytes +=3D bytes; } - ram_counters.transferred +=3D bytes; + stat64_add(&ram_atomic_counters.transferred, bytes); } =20 void dirty_sync_missed_zero_copy(void) @@ -753,7 +760,7 @@ void mig_throttle_counter_reset(void) =20 rs->time_last_bitmap_sync =3D qemu_clock_get_ms(QEMU_CLOCK_REALTIME); rs->num_dirty_pages_period =3D 0; - rs->bytes_xfer_prev =3D ram_counters.transferred; + rs->bytes_xfer_prev =3D stat64_get(&ram_atomic_counters.transferred); } =20 /** @@ -1113,8 +1120,9 @@ uint64_t ram_pagesize_summary(void) =20 uint64_t ram_get_total_transferred_pages(void) { - return ram_counters.normal + ram_counters.duplicate + - compression_counters.pages + xbzrle_counters.pages; + return stat64_get(&ram_atomic_counters.normal) + + stat64_get(&ram_atomic_counters.duplicate) + + compression_counters.pages + xbzrle_counters.pages; } =20 static void migration_update_rates(RAMState *rs, int64_t end_time) @@ -1173,8 +1181,8 @@ static void migration_trigger_throttle(RAMState *rs) { MigrationState *s =3D migrate_get_current(); uint64_t threshold =3D s->parameters.throttle_trigger_threshold; - - uint64_t bytes_xfer_period =3D ram_counters.transferred - rs->bytes_xf= er_prev; + uint64_t bytes_xfer_period =3D + stat64_get(&ram_atomic_counters.transferred) - rs->bytes_xfer_prev; uint64_t bytes_dirty_period =3D rs->num_dirty_pages_period * TARGET_PA= GE_SIZE; uint64_t bytes_dirty_threshold =3D bytes_xfer_period * threshold / 100; =20 @@ -1237,7 +1245,7 @@ static void migration_bitmap_sync(RAMState *rs) /* reset period counters */ rs->time_last_bitmap_sync =3D end_time; rs->num_dirty_pages_period =3D 0; - rs->bytes_xfer_prev =3D ram_counters.transferred; + rs->bytes_xfer_prev =3D stat64_get(&ram_atomic_counters.transferre= d); } if (migrate_use_events()) { qapi_event_send_migration_pass(ram_counters.dirty_sync_count); @@ -1313,7 +1321,7 @@ static int save_zero_page(RAMState *rs, RAMBlock *blo= ck, ram_addr_t offset) int len =3D save_zero_page_to_file(rs, rs->f, block, offset); =20 if (len) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); ram_transferred_add(len); return 1; } @@ -1350,9 +1358,9 @@ static bool control_save_page(RAMState *rs, RAMBlock = *block, ram_addr_t offset, } =20 if (bytes_xmit > 0) { - ram_counters.normal++; + stat64_add(&ram_atomic_counters.normal, 1); } else if (bytes_xmit =3D=3D 0) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); } =20 return true; @@ -1382,7 +1390,7 @@ static int save_normal_page(RAMState *rs, RAMBlock *b= lock, ram_addr_t offset, qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); } ram_transferred_add(TARGET_PAGE_SIZE); - ram_counters.normal++; + stat64_add(&ram_atomic_counters.normal, 1); return 1; } =20 @@ -1438,7 +1446,7 @@ static int ram_save_multifd_page(RAMState *rs, RAMBlo= ck *block, if (multifd_queue_page(rs->f, block, offset) < 0) { return -1; } - ram_counters.normal++; + stat64_add(&ram_atomic_counters.normal, 1); =20 return 1; } @@ -1476,7 +1484,7 @@ update_compress_thread_counts(const CompressParam *pa= ram, int bytes_xmit) ram_transferred_add(bytes_xmit); =20 if (param->zero_page) { - ram_counters.duplicate++; + stat64_add(&ram_atomic_counters.duplicate, 1); return; } =20 @@ -2651,9 +2659,9 @@ void acct_update_position(QEMUFile *f, size_t size, b= ool zero) uint64_t pages =3D size / TARGET_PAGE_SIZE; =20 if (zero) { - ram_counters.duplicate +=3D pages; + stat64_add(&ram_atomic_counters.duplicate, pages); } else { - ram_counters.normal +=3D pages; + stat64_add(&ram_atomic_counters.normal, pages); ram_transferred_add(size); qemu_file_credit_transfer(f, size); } --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527211; cv=none; d=zohomail.com; s=zohoarc; b=Gpj72YrXoyVDBCFmWRObulhiBuji1h/5hgLtw5SKbmxTRfUvn7QTNGuc6GePZP93grcEBGVuK/AOwPwyQ4f0vIYOlHp/jU08+21LGb2sWNFITQgrZschkX2stmVbPxaGTK2QYXG3T1e1bLEjyk4vTnFRfaAZdL8hHlbD8iES5jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527211; 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=pPVLt1FFk4NFFknElbElTfm7MmK8faBHIqzFIHqAXEY=; b=VVlLdjYGGFKG5H0w9rAFTOYqF3EQllcXDe1DeoMofr7lHpAy3TCY1h4a0VGpYlO6i82ZUSn34AVY12AkT/lNzhNK5RhEY23DpKhZeIXNP+3RNyv6fN0FrhTjwbmFxHCIg76hgicoa7yIVZ68eVVN1KCMVEQyMe7otZhkgJe8KSA= 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+importer=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 1668527211660402.515219504898; Tue, 15 Nov 2022 07:46:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzu-0006n8-RV; Tue, 15 Nov 2022 10:37:14 -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 1ouxzS-0006Ox-5v for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:46 -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 1ouxzO-0000Bt-Ss for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:45 -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-111-DCLhchthO0uLxjt0FPzrZQ-1; Tue, 15 Nov 2022 10:36:31 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5D63857F8F; Tue, 15 Nov 2022 15:36:30 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 153C12166B2B; Tue, 15 Nov 2022 15:36:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526602; 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=pPVLt1FFk4NFFknElbElTfm7MmK8faBHIqzFIHqAXEY=; b=VyoaYvGvtfhbe1osTA6tC7boHymsBmogorVvrhX5eh07FWwyQKIlS8dI+ZYGuKvhxzy+bl 2JNjfvLg07Ps2fjiXxtMBv0CD7Qj1LKdXY7bZCToVd8LMZmwNFIF+7LNDUxxLrM68vn8gR e5Joh+GLtsvmAV4aGUI3nKBBWB2R8yM= X-MC-Unique: DCLhchthO0uLxjt0FPzrZQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 22/30] migration: Teach PSS about host page Date: Tue, 15 Nov 2022 16:35:06 +0100 Message-Id: <20221115153514.28003-23-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527213815100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Migration code has a lot to do with host pages. Teaching PSS core about the idea of host page helps a lot and makes the code clean. Meanwhile, this prepares for the future changes that can leverage the new PSS helpers that this patch introduces to send host page in another thread. Three more fields are introduced for this: (1) host_page_sending: this is set to true when QEMU is sending a host page, false otherwise. (2) host_page_{start|end}: these point to the start/end of host page we're sending, and it's only valid when host_page_sending=3D=3Dtrue. For example, when we look up the next dirty page on the ramblock, with host_page_sending=3D=3Dtrue, we'll not try to look for anything beyond the current host page boundary. This can be slightly efficient than current code because currently we'll set pss->page to next dirty bit (which can be over current host page boundary) and reset it to host page boundary if we found it goes beyond that. With above, we can easily make migration_bitmap_find_dirty() self contained by updating pss->page properly. rs* parameter is removed because it's not even used in old code. When sending a host page, we should use the pss helpers like this: - pss_host_page_prepare(pss): called before sending host page - pss_within_range(pss): whether we're still working on the cur host page? - pss_host_page_finish(pss): called after sending a host page Then we can use ram_save_target_page() to save one small page. Currently ram_save_host_page() is still the only user. If there'll be another function to send host page (e.g. in return path thread) in the future, it should follow the same style. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 95 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 19 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 25fd3cf7dc..b71edf1f26 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -509,6 +509,11 @@ struct PageSearchStatus { * postcopy pages via postcopy preempt channel. */ bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Only valid if host_page_sendin= g=3D=3Dtrue */ + unsigned long host_page_start; + unsigned long host_page_end; }; typedef struct PageSearchStatus PageSearchStatus; =20 @@ -886,26 +891,38 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **c= urrent_data, } =20 /** - * migration_bitmap_find_dirty: find the next dirty page from start + * pss_find_next_dirty: find the next dirty page of current ramblock * - * Returns the page offset within memory region of the start of a dirty pa= ge + * This function updates pss->page to point to the next dirty page index + * within the ramblock to migrate, or the end of ramblock when nothing + * found. Note that when pss->host_page_sending=3D=3Dtrue it means we're + * during sending a host page, so we won't look for dirty page that is + * outside the host page boundary. * - * @rs: current RAM state - * @rb: RAMBlock where to search for dirty pages - * @start: page where we start the search + * @pss: the current page search status */ -static inline -unsigned long migration_bitmap_find_dirty(RAMState *rs, RAMBlock *rb, - unsigned long start) +static void pss_find_next_dirty(PageSearchStatus *pss) { + RAMBlock *rb =3D pss->block; unsigned long size =3D rb->used_length >> TARGET_PAGE_BITS; unsigned long *bitmap =3D rb->bmap; =20 if (ramblock_is_ignored(rb)) { - return size; + /* Points directly to the end, so we know no dirty page */ + pss->page =3D size; + return; } =20 - return find_next_bit(bitmap, size, start); + /* + * If during sending a host page, only look for dirty pages within the + * current host page being send. + */ + if (pss->host_page_sending) { + assert(pss->host_page_end); + size =3D MIN(size, pss->host_page_end); + } + + pss->page =3D find_next_bit(bitmap, size, pss->page); } =20 static void migration_clear_memory_region_dirty_bitmap(RAMBlock *rb, @@ -1591,7 +1608,9 @@ static bool find_dirty_block(RAMState *rs, PageSearch= Status *pss, bool *again) pss->postcopy_requested =3D false; pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; =20 - pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->page); + /* Update pss->page for the next dirty bit in ramblock */ + pss_find_next_dirty(pss); + if (pss->complete_round && pss->block =3D=3D rs->last_seen_block && pss->page >=3D rs->last_page) { /* @@ -2480,6 +2499,44 @@ static void postcopy_preempt_reset_channel(RAMState = *rs) } } =20 +/* Should be called before sending a host page */ +static void pss_host_page_prepare(PageSearchStatus *pss) +{ + /* How many guest pages are there in one host page? */ + size_t guest_pfns =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BIT= S; + + 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); +} + +/* + * Whether the page pointed by PSS is within the host page being sent. + * Must be called after a previous pss_host_page_prepare(). + */ +static bool pss_within_range(PageSearchStatus *pss) +{ + ram_addr_t ram_addr; + + assert(pss->host_page_sending); + + /* Over host-page boundary? */ + if (pss->page >=3D pss->host_page_end) { + return false; + } + + ram_addr =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; + + return offset_in_ramblock(pss->block, ram_addr); +} + +static void pss_host_page_finish(PageSearchStatus *pss) +{ + pss->host_page_sending =3D false; + /* This is not needed, but just to reset it */ + pss->host_page_start =3D pss->host_page_end =3D 0; +} + /** * ram_save_host_page: save a whole host page * @@ -2507,8 +2564,6 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) int tmppages, pages =3D 0; size_t pagesize_bits =3D qemu_ram_pagesize(pss->block) >> TARGET_PAGE_BITS; - unsigned long hostpage_boundary =3D - QEMU_ALIGN_UP(pss->page + 1, pagesize_bits); unsigned long start_page =3D pss->page; int res; =20 @@ -2521,6 +2576,9 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) postcopy_preempt_choose_channel(rs, pss); } =20 + /* Update host page boundary information */ + pss_host_page_prepare(pss); + do { if (postcopy_needs_preempt(rs, pss)) { postcopy_do_preempt(rs, pss); @@ -2558,15 +2616,14 @@ static int ram_save_host_page(RAMState *rs, PageSea= rchStatus *pss) } =20 if (tmppages < 0) { + pss_host_page_finish(pss); return tmppages; } =20 - pss->page =3D migration_bitmap_find_dirty(rs, pss->block, pss->pag= e); - } while ((pss->page < hostpage_boundary) && - offset_in_ramblock(pss->block, - ((ram_addr_t)pss->page) << TARGET_PAGE_BIT= S)); - /* The offset we leave with is the min boundary of host page and block= */ - pss->page =3D MIN(pss->page, hostpage_boundary); + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); + + pss_host_page_finish(pss); =20 /* * When with postcopy preempt mode, flush the data as soon as possible= for --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527069; cv=none; d=zohomail.com; s=zohoarc; b=JIjXDbZJ/9eZ8FQs+XPh7ZcNzu64+NxX9FPwrRYL1YTtEv9MImdWQMyU+qbkpIPZx6YWKgsaJeCRBKQDsHCMeHTFP1yXjNdAdN86TMpPGcMnleZ1hJKR8L0S8+lBHfOcf1tOvd8kAXfdabxN8qb6/SCtesV7ABZrRxXjqSeo09c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527069; 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=vc4jePGJ0dJqQFoDpTyZZcFF7OspZ5JDVTcFE7uLxpc=; b=T7XS41Y0wWtHz3vrUHVYvcfyNFbiSaPUyrc5GvvDwAKABZNBZHtHdSpwzp4lP11/23MBDWteJ+gmk4L4L3+zgeolm5A5PmUELm2ysi54GrnESZCbfU+5E/1OP3tNqbIiFTmErGgePplOxQV8ZRpUemLwEJfxtTdak54h8+d7fTI= 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+importer=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 1668527069203436.99186165785443; Tue, 15 Nov 2022 07:44:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzs-0006f0-RA; Tue, 15 Nov 2022 10:37: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 1ouxzP-0006Jq-6q for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:43 -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 1ouxzK-0000AD-5I for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:40 -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-505-Ak3509DXPKqSU0l9UgQbdA-1; Tue, 15 Nov 2022 10:36:34 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BCA893817A67; Tue, 15 Nov 2022 15:36:33 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B96E2166B2C; Tue, 15 Nov 2022 15:36:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526597; 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=vc4jePGJ0dJqQFoDpTyZZcFF7OspZ5JDVTcFE7uLxpc=; b=SWrl8UnIs9HEcbF3KHnNlsS4takhkg8YcqWY4idsSdemamuVMBEizBzuP8jiHFDBbDdrxG 7Z5McFzj6SgRPOcziPcf+nXCD9gJp5zb/Jh+gP5J2Uq0/ITij1yxPyvs2ibmj6aHzT0m+/ 63CI3oCgnmjXZKneg5ITXhepXaSKuIw= X-MC-Unique: Ak3509DXPKqSU0l9UgQbdA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 23/30] migration: Introduce pss_channel Date: Tue, 15 Nov 2022 16:35:07 +0100 Message-Id: <20221115153514.28003-24-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527071170100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Introduce pss_channel for PageSearchStatus, define it as "the migration channel to be used to transfer this host page". We used to have rs->f, which is a mirror to MigrationState.to_dst_file. After postcopy preempt initial version, rs->f can be dynamically changed depending on which channel we want to use. But that later work still doesn't grant full concurrency of sending pages in e.g. different threads, because rs->f can either be the PRECOPY channel or POSTCOPY channel. This needs to be per-thread too. PageSearchStatus is actually a good piece of struct which we can leverage if we want to have multiple threads sending pages. Sending a single guest page may not make sense, so we make the granule to be "host page", and in the PSS structure we allow specify a QEMUFile* to migrate a specific host page. Then we open the possibility to specify different channels in different threads with different PSS structures. The PSS prefix can be slightly misleading here because e.g. for the upcoming usage of postcopy channel/thread it's not "searching" (or, scanning) at all but sending the explicit page that was requested. However since PSS existed for some years keep it as-is until someone complains. This patch mostly (simply) replace rs->f with pss->pss_channel only. No functional change intended for this patch yet. But it does prepare to finally drop rs->f, and make ram_save_guest_page() thread safe. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 70 +++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index b71edf1f26..fedd61b3da 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -481,6 +481,8 @@ void dirty_sync_missed_zero_copy(void) =20 /* used by the search for pages to send */ struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -803,9 +805,9 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_ad= dr_t current_addr) * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, uint8_t **current_data, - ram_addr_t current_addr, RAMBlock *block, - ram_addr_t offset) +static int save_xbzrle_page(RAMState *rs, QEMUFile *file, + uint8_t **current_data, ram_addr_t current_add= r, + RAMBlock *block, ram_addr_t offset) { int encoded_len =3D 0, bytes_xbzrle; uint8_t *prev_cached_page; @@ -873,11 +875,11 @@ static int save_xbzrle_page(RAMState *rs, uint8_t **c= urrent_data, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(rs, rs->f, block, + bytes_xbzrle =3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_XBZRLE); - qemu_put_byte(rs->f, ENCODING_FLAG_XBZRLE); - qemu_put_be16(rs->f, encoded_len); - qemu_put_buffer(rs->f, XBZRLE.encoded_buf, encoded_len); + qemu_put_byte(file, ENCODING_FLAG_XBZRLE); + qemu_put_be16(file, encoded_len); + qemu_put_buffer(file, XBZRLE.encoded_buf, encoded_len); bytes_xbzrle +=3D encoded_len + 1 + 2; /* * Like compressed_size (please see update_compress_thread_counts), @@ -1333,9 +1335,10 @@ static int save_zero_page_to_file(RAMState *rs, QEMU= File *file, * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) +static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset) { - int len =3D save_zero_page_to_file(rs, rs->f, block, offset); + int len =3D save_zero_page_to_file(rs, file, block, offset); =20 if (len) { stat64_add(&ram_atomic_counters.duplicate, 1); @@ -1352,15 +1355,15 @@ static int save_zero_page(RAMState *rs, RAMBlock *b= lock, ram_addr_t offset) * * Return true if the pages has been saved, otherwise false is returned. */ -static bool control_save_page(RAMState *rs, RAMBlock *block, ram_addr_t of= fset, - int *pages) +static bool control_save_page(PageSearchStatus *pss, RAMBlock *block, + ram_addr_t offset, int *pages) { uint64_t bytes_xmit =3D 0; int ret; =20 *pages =3D -1; - ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAG= E_SIZE, - &bytes_xmit); + ret =3D ram_control_save_page(pss->pss_channel, block->offset, offset, + TARGET_PAGE_SIZE, &bytes_xmit); if (ret =3D=3D RAM_SAVE_CONTROL_NOT_SUPP) { return false; } @@ -1394,17 +1397,17 @@ static bool control_save_page(RAMState *rs, RAMBloc= k *block, ram_addr_t offset, * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, RAMBlock *block, ram_addr_t offs= et, - uint8_t *buf, bool async) +static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, + ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, rs->f, block, + ram_transferred_add(save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { - qemu_put_buffer_async(rs->f, buf, TARGET_PAGE_SIZE, + qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, migrate_release_ram() && migration_in_postcopy()); } else { - qemu_put_buffer(rs->f, buf, TARGET_PAGE_SIZE); + qemu_put_buffer(file, buf, TARGET_PAGE_SIZE); } ram_transferred_add(TARGET_PAGE_SIZE); stat64_add(&ram_atomic_counters.normal, 1); @@ -1437,8 +1440,8 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages =3D save_xbzrle_page(rs, &p, current_addr, block, - offset); + pages =3D save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page * might get updated before it gets to the wire @@ -1449,7 +1452,8 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - pages =3D save_normal_page(rs, block, offset, p, send_async); + pages =3D save_normal_page(rs, pss->pss_channel, block, offset, + p, send_async); } =20 XBZRLE_cache_unlock(); @@ -1457,10 +1461,10 @@ static int ram_save_page(RAMState *rs, PageSearchSt= atus *pss) return pages; } =20 -static int ram_save_multifd_page(RAMState *rs, RAMBlock *block, +static int ram_save_multifd_page(QEMUFile *file, RAMBlock *block, ram_addr_t offset) { - if (multifd_queue_page(rs->f, block, offset) < 0) { + if (multifd_queue_page(file, block, offset) < 0) { return -1; } stat64_add(&ram_atomic_counters.normal, 1); @@ -1755,7 +1759,7 @@ static int ram_save_release_protection(RAMState *rs, = PageSearchStatus *pss, uint64_t run_length =3D (pss->page - start_page) << TARGET_PAGE_BI= TS; =20 /* Flush async buffers before un-protect. */ - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); /* Un-protect memory range. */ res =3D uffd_change_protection(rs->uffdio_fd, page_address, run_le= ngth, false, false); @@ -2342,7 +2346,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) ram_addr_t offset =3D ((ram_addr_t)pss->page) << TARGET_PAGE_BITS; int res; =20 - if (control_save_page(rs, block, offset, &res)) { + if (control_save_page(pss, block, offset, &res)) { return res; } =20 @@ -2350,7 +2354,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) return 1; } =20 - res =3D save_zero_page(rs, block, offset); + res =3D save_zero_page(rs, pss->pss_channel, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2370,7 +2374,7 @@ static int ram_save_target_page(RAMState *rs, PageSea= rchStatus *pss) * still see partially copied pages which is data corruption. */ if (migrate_use_multifd() && !migration_in_postcopy()) { - return ram_save_multifd_page(rs, block, offset); + return ram_save_multifd_page(pss->pss_channel, block, offset); } =20 return ram_save_page(rs, pss); @@ -2572,10 +2576,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) return 0; } =20 - if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, pss); - } - /* Update host page boundary information */ pss_host_page_prepare(pss); =20 @@ -2635,7 +2635,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) * explicit flush or it won't flush until the buffer is full. */ if (migrate_postcopy_preempt() && pss->postcopy_requested) { - qemu_fflush(rs->f); + qemu_fflush(pss->pss_channel); } =20 res =3D ram_save_release_protection(rs, pss, start_page); @@ -2701,6 +2701,12 @@ static int ram_find_and_save_block(RAMState *rs) } =20 if (found) { + /* Update rs->f with correct channel */ + if (postcopy_preempt_active()) { + postcopy_preempt_choose_channel(rs, &pss); + } + /* Cache rs->f in pss_channel (TODO: remove rs->f) */ + pss.pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, &pss); } } while (!pages && again); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527251; cv=none; d=zohomail.com; s=zohoarc; b=SnDlnLbMWsqhrNn0Sw56mrIw9hhHuNq8ia0zBa9sMIi61gFReyIUd42bz4Qcm/DO2TD3FgxTRIAH1saxLFWg8FFY+r92DzgR+le/aZkMrKXveM7+i+uYe1qXneisP7pP//8cxcwvYgPtTSxHenW37OGdOyA71WTzmtmYlkRGZV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527251; 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=EluQm/oTez6ahm2nd0eMnYBKfql0vE5ySiQGTIRw4dM=; b=PJz3uT46xohrtbYCnkI1za8k6gcY4e4mgtrCYqlR7kcvQgxOq+697t4n8aWC+F8/9zyd0oDFosClxur7CUSp5//GuyGVsqq5zP6Ied5mDPlQknC6GkeREqMrlWnf2QAPZMzOZIsX0h50BPa2YIKJwV/Xk7eaypETRmxzUd321Nc= 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+importer=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 1668527251353645.077675643205; Tue, 15 Nov 2022 07:47:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzs-0006ew-SL; Tue, 15 Nov 2022 10:37: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 1ouxzN-0006Hj-16 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:42 -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 1ouxzK-0000AM-NO for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:40 -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-308-WjGN9nu8N7ORcbYUHnErNQ-1; Tue, 15 Nov 2022 10:36:37 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 995D73817A6A; Tue, 15 Nov 2022 15:36:36 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10A9F2166B2B; Tue, 15 Nov 2022 15:36:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526598; 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=EluQm/oTez6ahm2nd0eMnYBKfql0vE5ySiQGTIRw4dM=; b=JzKCErUF58JXabJauh4V9tJJ6v9vXYo+z4dof6VbH/dVPDHyVbfbn770IezpsfiWE0NVKq 7jS+imOJccB0oPx8G9Crfm2KG80CiELoL9pKf3Ia/QKlIwJmmqxg4ip4G8w6GhLP4NRvIa IKZ73lElIRbO9cYTDTOjJvJPxHJG54I= X-MC-Unique: WjGN9nu8N7ORcbYUHnErNQ-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 24/30] migration: Add pss_init() Date: Tue, 15 Nov 2022 16:35:08 +0100 Message-Id: <20221115153514.28003-25-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527251993100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Helper to init PSS structures. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index fedd61b3da..a2e86623d3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -570,6 +570,14 @@ static bool do_compress_ram_page(QEMUFile *f, z_stream= *stream, RAMBlock *block, static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, bool postcopy_requested); =20 +/* NOTE: page is the PFN not real ram_addr_t. */ +static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) +{ + pss->block =3D rb; + pss->page =3D page; + pss->complete_round =3D false; +} + static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; @@ -2678,9 +2686,7 @@ static int ram_find_and_save_block(RAMState *rs) rs->last_page =3D 0; } =20 - pss.block =3D rs->last_seen_block; - pss.page =3D rs->last_page; - pss.complete_round =3D false; + pss_init(&pss, rs->last_seen_block, rs->last_page); =20 do { again =3D true; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527073; cv=none; d=zohomail.com; s=zohoarc; b=CVGVwY+IgbpIIHXIipwKJEdzfKj53OGDboV4tpiEYjErczLk0TsUrXL4FS2gtoMth+kgJ8g9iyMiDItLEZp04XxcZO/Kn++Jcoxt+YGccFaLDZxpcoIOHRBtnwvZuam7LxUr+eDCGzKErupGnnrVWFzHkfj3gOJzwhZaIHYFFkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527073; 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=koB3/mhLtylayQQdlhc6KiXJbQSyj75F0fbwswMjY8o=; b=iIDJLkUD4oG8/bcZWvnmnQODXmHLFJ5yZqvtcldcPe7Y9uKMh+th25MaqrxgKkZUF3XOoJvPvAyIIcGrr7otmdr+FbfERo8KSbexbh3uOTBse2wsZ+ei27O5PBO7taXQ0M/vALGcqoVJ1CGilqy3Hh23FH8tWZfQ7gP0qarU0W0= 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+importer=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 1668527073932276.9156312429641; Tue, 15 Nov 2022 07:44:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzu-0006lV-5N; Tue, 15 Nov 2022 10:37:14 -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 1ouxzT-0006R7-K6 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:47 -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 1ouxzQ-0000En-Pr for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:47 -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-187-Bnwie79kMeKS7f_26BIt_Q-1; Tue, 15 Nov 2022 10:36:40 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F81D85A5A6; Tue, 15 Nov 2022 15:36:39 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFB7C2166B2B; Tue, 15 Nov 2022 15:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526604; 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=koB3/mhLtylayQQdlhc6KiXJbQSyj75F0fbwswMjY8o=; b=ibGwDW9y8tC8rj8Sk0NO8UV37MV5ZCcofcWysePvvtzan+qhDTDjCfMa9A+aEFXv9bMZ3o 6cFC+Nxws0mc/YUYQSPRVqonEJDeTk0nO8cm4074KTEKJ8QhfttXIi8E8tOedw2biJ8Yq9 t1sfZKzgr07xFyGjmzYt903+7lSVQ+Y= X-MC-Unique: Bnwie79kMeKS7f_26BIt_Q-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 25/30] migration: Make PageSearchStatus part of RAMState Date: Tue, 15 Nov 2022 16:35:09 +0100 Message-Id: <20221115153514.28003-26-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527075181100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu We used to allocate PSS structure on the stack for precopy when sending pages. Make it static, so as to describe per-channel ram migration status. Here we declared RAM_CHANNEL_MAX instances, preparing for postcopy to use it, even though this patch has not yet to start using the 2nd instance. This should not have any functional change per se, but it already starts to export PSS information via the RAMState, so that e.g. one PSS channel can start to reference the other PSS channel. Always protect PSS access using the same RAMState.bitmap_mutex. We already do so, so no code change needed, just some comment update. Maybe we should consider renaming bitmap_mutex some day as it's going to be a more commonly and big mutex we use for ram states, but just leave it for later. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 112 ++++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 51 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index a2e86623d3..bdb29ac4d9 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -113,6 +113,46 @@ static void __attribute__((constructor)) init_cpu_flag= (void) =20 XBZRLECacheStats xbzrle_counters; =20 +/* used by the search for pages to send */ +struct PageSearchStatus { + /* The migration channel used for a specific host page */ + QEMUFile *pss_channel; + /* Current block being searched */ + RAMBlock *block; + /* Current page to search from */ + unsigned long page; + /* Set once we wrap around */ + bool complete_round; + /* + * [POSTCOPY-ONLY] Whether current page is explicitly requested by + * postcopy. When set, the request is "urgent" because the dest QEMU + * threads are waiting for us. + */ + bool postcopy_requested; + /* + * [POSTCOPY-ONLY] The target channel to use to send current page. + * + * Note: This may _not_ match with the value in postcopy_requested + * above. Let's imagine the case where the postcopy request is exactly + * the page that we're sending in progress during precopy. In this case + * we'll have postcopy_requested set to true but the target channel + * will be the precopy channel (so that we don't split brain on that + * specific page since the precopy channel already contains partial of + * that page data). + * + * Besides that specific use case, postcopy_target_channel should + * always be equal to postcopy_requested, because by default we send + * postcopy pages via postcopy preempt channel. + */ + bool postcopy_target_channel; + /* Whether we're sending a host page */ + bool host_page_sending; + /* The start/end of current host page. Invalid if host_page_sending= =3D=3Dfalse */ + unsigned long host_page_start; + unsigned long host_page_end; +}; +typedef struct PageSearchStatus PageSearchStatus; + /* struct contains XBZRLE cache and a static page used by the compression */ static struct { @@ -347,6 +387,11 @@ typedef struct { struct RAMState { /* QEMUFile used for this migration */ QEMUFile *f; + /* + * PageSearchStatus structures for the channels when send pages. + * Protected by the bitmap_mutex. + */ + PageSearchStatus pss[RAM_CHANNEL_MAX]; /* UFFD file descriptor, used in 'write-tracking' migration */ int uffdio_fd; /* Last block that we have visited searching for dirty pages */ @@ -390,7 +435,12 @@ struct RAMState { uint64_t target_page_count; /* number of dirty bits in the bitmap */ uint64_t migration_dirty_pages; - /* Protects modification of the bitmap and migration dirty pages */ + /* + * Protects: + * - dirty/clear bitmap + * - migration_dirty_pages + * - pss structures + */ QemuMutex bitmap_mutex; /* The RAMBlock used in the last src_page_requests */ RAMBlock *last_req_rb; @@ -479,46 +529,6 @@ void dirty_sync_missed_zero_copy(void) ram_counters.dirty_sync_missed_zero_copy++; } =20 -/* used by the search for pages to send */ -struct PageSearchStatus { - /* The migration channel used for a specific host page */ - QEMUFile *pss_channel; - /* Current block being searched */ - RAMBlock *block; - /* Current page to search from */ - unsigned long page; - /* Set once we wrap around */ - bool complete_round; - /* - * [POSTCOPY-ONLY] Whether current page is explicitly requested by - * postcopy. When set, the request is "urgent" because the dest QEMU - * threads are waiting for us. - */ - bool postcopy_requested; - /* - * [POSTCOPY-ONLY] The target channel to use to send current page. - * - * Note: This may _not_ match with the value in postcopy_requested - * above. Let's imagine the case where the postcopy request is exactly - * the page that we're sending in progress during precopy. In this case - * we'll have postcopy_requested set to true but the target channel - * will be the precopy channel (so that we don't split brain on that - * specific page since the precopy channel already contains partial of - * that page data). - * - * Besides that specific use case, postcopy_target_channel should - * always be equal to postcopy_requested, because by default we send - * postcopy pages via postcopy preempt channel. - */ - bool postcopy_target_channel; - /* Whether we're sending a host page */ - bool host_page_sending; - /* The start/end of current host page. Only valid if host_page_sendin= g=3D=3Dtrue */ - unsigned long host_page_start; - unsigned long host_page_end; -}; -typedef struct PageSearchStatus PageSearchStatus; - CompressionStats compression_counters; =20 struct CompressParam { @@ -2665,7 +2675,7 @@ static int ram_save_host_page(RAMState *rs, PageSearc= hStatus *pss) */ static int ram_find_and_save_block(RAMState *rs) { - PageSearchStatus pss; + PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; int pages =3D 0; bool again, found; =20 @@ -2686,11 +2696,11 @@ static int ram_find_and_save_block(RAMState *rs) rs->last_page =3D 0; } =20 - pss_init(&pss, rs->last_seen_block, rs->last_page); + pss_init(pss, rs->last_seen_block, rs->last_page); =20 do { again =3D true; - found =3D get_queued_page(rs, &pss); + found =3D get_queued_page(rs, pss); =20 if (!found) { /* @@ -2698,27 +2708,27 @@ static int ram_find_and_save_block(RAMState *rs) * preempted precopy. Otherwise find the next dirty bit. */ if (postcopy_preempt_triggered(rs)) { - postcopy_preempt_restore(rs, &pss, false); + postcopy_preempt_restore(rs, pss, false); found =3D true; } else { /* priority queue empty, so just search for something dirt= y */ - found =3D find_dirty_block(rs, &pss, &again); + found =3D find_dirty_block(rs, pss, &again); } } =20 if (found) { /* Update rs->f with correct channel */ if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, &pss); + postcopy_preempt_choose_channel(rs, pss); } /* Cache rs->f in pss_channel (TODO: remove rs->f) */ - pss.pss_channel =3D rs->f; - pages =3D ram_save_host_page(rs, &pss); + pss->pss_channel =3D rs->f; + pages =3D ram_save_host_page(rs, pss); } } while (!pages && again); =20 - rs->last_seen_block =3D pss.block; - rs->last_page =3D pss.page; + rs->last_seen_block =3D pss->block; + rs->last_page =3D pss->page; =20 return pages; } --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526685; cv=none; d=zohomail.com; s=zohoarc; b=d9amxbGd8l4hpUoFOo5gVtbcDfqu86kCYrGIUeauOiYPFZlKXDLJZhpNuPK3iSFzoiTSR0w+W0flwBH1FMGOaciN5jyHi5I3CCVEI8KUgvW8tiN38vDPTrhEMB/k0SPMMDpmtP4VvDBLTxuiVEJpm4grI4uajEGTrkeFOTF7LG0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526685; 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=vtXCnDGaRnnyELakwPKO/beDwfFW1BQewDUw+d86FIM=; b=BuxRU5GjofvehcqKUkzTkCEXiBxq/lcwltzDcvI+3ov0tjw/vqoJQM/xy+vaDL1uxwMWjcPodAL6lgfwmQYVwqeDvmfmleagnwhj00T8mRP8GX3DbtNj/Rj7Vm0+G1pbjVUxSvgnYJBOBIOJNSXlMygPWyW0m0oPGi2aoM1+6pw= 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+importer=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 1668526685697859.6584389648712; Tue, 15 Nov 2022 07:38:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzw-0006rx-Uc; Tue, 15 Nov 2022 10:37:17 -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 1ouxza-0006ZI-CW for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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 1ouxzY-0000Kw-GO for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36: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-649-BJBWr0yMOYqfyh0HqS9oUA-1; Tue, 15 Nov 2022 10:36:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CF1C101A528; Tue, 15 Nov 2022 15:36:42 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBD222166B37; Tue, 15 Nov 2022 15:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526611; 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=vtXCnDGaRnnyELakwPKO/beDwfFW1BQewDUw+d86FIM=; b=WEPa1hhPYGz5+2D6FEDWcW9LNwhz2SaX14tr84+tb6abAnQozDdRZa8LFkZzWJVEyDKy17 SaRDUon/X8eyY1KZwyqg1HG2jGrWydtygJDDEVyiFEYX/CF5mr8a5DjGx4WWB+0OpSDQWs qtM6/FvXOZ9FbLZcfb17F4b8TwQDt6E= X-MC-Unique: BJBWr0yMOYqfyh0HqS9oUA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 26/30] migration: Move last_sent_block into PageSearchStatus Date: Tue, 15 Nov 2022 16:35:10 +0100 Message-Id: <20221115153514.28003-27-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526687273100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu Since we use PageSearchStatus to represent a channel, it makes perfect sense to keep last_sent_block (aka, leverage RAM_SAVE_FLAG_CONTINUE) to be per-channel rather than global because each channel can be sending different pages on ramblocks. Hence move it from RAMState into PageSearchStatus. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 71 ++++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index bdb29ac4d9..dbdde5a6a5 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -117,6 +117,8 @@ XBZRLECacheStats xbzrle_counters; struct PageSearchStatus { /* The migration channel used for a specific host page */ QEMUFile *pss_channel; + /* Last block from where we have sent data */ + RAMBlock *last_sent_block; /* Current block being searched */ RAMBlock *block; /* Current page to search from */ @@ -396,8 +398,6 @@ struct RAMState { int uffdio_fd; /* Last block that we have visited searching for dirty pages */ RAMBlock *last_seen_block; - /* Last block from where we have sent data */ - RAMBlock *last_sent_block; /* Last dirty target page we have sent */ ram_addr_t last_page; /* last ram version we have seen */ @@ -712,16 +712,17 @@ exit: * * Returns the number of bytes written * - * @f: QEMUFile where to send the data + * @pss: current PSS channel status * @block: block that contains the page we want to send * @offset: offset inside the block for the page * in the lower bits, it contains flags */ -static size_t save_page_header(RAMState *rs, QEMUFile *f, RAMBlock *block, +static size_t save_page_header(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { size_t size, len; - bool same_block =3D (block =3D=3D rs->last_sent_block); + bool same_block =3D (block =3D=3D pss->last_sent_block); + QEMUFile *f =3D pss->pss_channel; =20 if (same_block) { offset |=3D RAM_SAVE_FLAG_CONTINUE; @@ -734,7 +735,7 @@ static size_t save_page_header(RAMState *rs, QEMUFile *= f, RAMBlock *block, qemu_put_byte(f, len); qemu_put_buffer(f, (uint8_t *)block->idstr, len); size +=3D 1 + len; - rs->last_sent_block =3D block; + pss->last_sent_block =3D block; } return size; } @@ -818,17 +819,19 @@ static void xbzrle_cache_zero_page(RAMState *rs, ram_= addr_t current_addr) * -1 means that xbzrle would be longer than normal * * @rs: current RAM state + * @pss: current PSS channel * @current_data: pointer to the address of the page contents * @current_addr: addr of the page * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_xbzrle_page(RAMState *rs, QEMUFile *file, +static int save_xbzrle_page(RAMState *rs, PageSearchStatus *pss, uint8_t **current_data, ram_addr_t current_add= r, RAMBlock *block, ram_addr_t offset) { int encoded_len =3D 0, bytes_xbzrle; uint8_t *prev_cached_page; + QEMUFile *file =3D pss->pss_channel; =20 if (!cache_is_cached(XBZRLE.cache, current_addr, ram_counters.dirty_sync_count)) { @@ -893,7 +896,7 @@ static int save_xbzrle_page(RAMState *rs, QEMUFile *fil= e, } =20 /* Send XBZRLE based compressed page */ - bytes_xbzrle =3D save_page_header(rs, file, block, + bytes_xbzrle =3D save_page_header(pss, block, offset | RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(file, ENCODING_FLAG_XBZRLE); qemu_put_be16(file, encoded_len); @@ -1324,19 +1327,19 @@ void ram_release_page(const char *rbname, uint64_t = offset) * Returns the size of data written to the file, 0 means the page is not * a zero page * - * @rs: current RAM state - * @file: the file where the data is saved + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page_to_file(RAMState *rs, QEMUFile *file, +static int save_zero_page_to_file(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { uint8_t *p =3D block->host + offset; + QEMUFile *file =3D pss->pss_channel; int len =3D 0; =20 if (buffer_is_zero(p, TARGET_PAGE_SIZE)) { - len +=3D save_page_header(rs, file, block, offset | RAM_SAVE_FLAG_= ZERO); + len +=3D save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO); qemu_put_byte(file, 0); len +=3D 1; ram_release_page(block->idstr, offset); @@ -1349,14 +1352,14 @@ static int save_zero_page_to_file(RAMState *rs, QEM= UFile *file, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page */ -static int save_zero_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_zero_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset) { - int len =3D save_zero_page_to_file(rs, file, block, offset); + int len =3D save_zero_page_to_file(pss, block, offset); =20 if (len) { stat64_add(&ram_atomic_counters.duplicate, 1); @@ -1409,16 +1412,18 @@ static bool control_save_page(PageSearchStatus *pss= , RAMBlock *block, * * Returns the number of pages written. * - * @rs: current RAM state + * @pss: current PSS channel * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @buf: the page to be sent * @async: send to page asyncly */ -static int save_normal_page(RAMState *rs, QEMUFile *file, RAMBlock *block, +static int save_normal_page(PageSearchStatus *pss, RAMBlock *block, ram_addr_t offset, uint8_t *buf, bool async) { - ram_transferred_add(save_page_header(rs, file, block, + QEMUFile *file =3D pss->pss_channel; + + ram_transferred_add(save_page_header(pss, block, offset | RAM_SAVE_FLAG_PAGE)); if (async) { qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE, @@ -1458,7 +1463,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 XBZRLE_cache_lock(); if (rs->xbzrle_enabled && !migration_in_postcopy()) { - pages =3D save_xbzrle_page(rs, pss->pss_channel, &p, current_addr, + pages =3D save_xbzrle_page(rs, pss, &p, current_addr, block, offset); if (!rs->last_stage) { /* Can't send this cached data async, since the cache page @@ -1470,8 +1475,7 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss) =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - pages =3D save_normal_page(rs, pss->pss_channel, block, offset, - p, send_async); + pages =3D save_normal_page(pss, block, offset, p, send_async); } =20 XBZRLE_cache_unlock(); @@ -1494,14 +1498,15 @@ static bool do_compress_ram_page(QEMUFile *f, z_str= eam *stream, RAMBlock *block, ram_addr_t offset, uint8_t *source_buf) { RAMState *rs =3D ram_state; + PageSearchStatus *pss =3D &rs->pss[RAM_CHANNEL_PRECOPY]; uint8_t *p =3D block->host + offset; int ret; =20 - if (save_zero_page_to_file(rs, f, block, offset)) { + if (save_zero_page_to_file(pss, block, offset)) { return true; } =20 - save_page_header(rs, f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); + save_page_header(pss, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); =20 /* * copy it to a internal buffer to avoid it being modified by VM @@ -2321,7 +2326,8 @@ static bool save_page_use_compression(RAMState *rs) * has been properly handled by compression, otherwise needs other * paths to handle it */ -static bool save_compress_page(RAMState *rs, RAMBlock *block, ram_addr_t o= ffset) +static bool save_compress_page(RAMState *rs, PageSearchStatus *pss, + RAMBlock *block, ram_addr_t offset) { if (!save_page_use_compression(rs)) { return false; @@ -2337,7 +2343,7 @@ static bool save_compress_page(RAMState *rs, RAMBlock= *block, ram_addr_t offset) * We post the fist page as normal page as compression will take * much CPU resource. */ - if (block !=3D rs->last_sent_block) { + if (block !=3D pss->last_sent_block) { flush_compressed_data(rs); return false; } @@ -2368,11 +2374,11 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return res; } =20 - if (save_compress_page(rs, block, offset)) { + if (save_compress_page(rs, pss, block, offset)) { return 1; } =20 - res =3D save_zero_page(rs, pss->pss_channel, block, offset); + res =3D save_zero_page(pss, block, offset); if (res > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -2503,7 +2509,7 @@ static void postcopy_preempt_choose_channel(RAMState = *rs, PageSearchStatus *pss) * If channel switched, reset last_sent_block since the old sent b= lock * may not be on the same channel. */ - rs->last_sent_block =3D NULL; + pss->last_sent_block =3D NULL; =20 trace_postcopy_preempt_switch_channel(channel); } @@ -2842,8 +2848,13 @@ static void ram_save_cleanup(void *opaque) =20 static void ram_state_reset(RAMState *rs) { + int i; + + for (i =3D 0; i < RAM_CHANNEL_MAX; i++) { + rs->pss[i].last_sent_block =3D NULL; + } + rs->last_seen_block =3D NULL; - rs->last_sent_block =3D NULL; rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; @@ -3037,8 +3048,8 @@ void ram_postcopy_send_discard_bitmap(MigrationState = *ms) migration_bitmap_sync(rs); =20 /* Easiest way to make sure we don't resume in the middle of a host-pa= ge */ + rs->pss[RAM_CHANNEL_PRECOPY].last_sent_block =3D NULL; rs->last_seen_block =3D NULL; - rs->last_sent_block =3D NULL; rs->last_page =3D 0; =20 postcopy_each_ram_send_discard(ms); --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527954; cv=none; d=zohomail.com; s=zohoarc; b=b8rnteWZASkzNiY2lTQn5IZxcYuEeWdXtI6huDv+DBJhim7+WPNJf4WftkYjoh+mGJMw8ftP0nywDofisJgWWBfo1M1aoNaN6Y32LNOR6iDCGNL3QS279PkiaVDRf+YTe+9O7v2asxKvR6A9/k/HCPKyica9IXajDrqdHUO0FZ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527954; 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=G+CMx7bhHy1RPM7Isd3Dgm8HDohp+a70XZsFhHXa7dk=; b=GKM7vMcrIqx5n05iLO1OjFOtiP+IdoTovHyFZLbLRhDzOLPBPMSS6B5451rTs5bLxBK4NrF4RgqDcNm2+sS82NIzY1lyCF/w1DVMknubyjbxCTSv5+9q8QxEuzpYe+k30wERRzzUGmyG+FNOqqcfqDhFSEFbiGjpClxe9IqNtVs= 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+importer=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 166852795415488.84469003377512; Tue, 15 Nov 2022 07:59:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzv-0006p9-VG; Tue, 15 Nov 2022 10:37:16 -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 1ouxzZ-0006ZF-Sn for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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 1ouxzY-0000Jj-3f for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:36:53 -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-639-Ie1gEk3UPp6WSAC9Fn_Bmw-1; Tue, 15 Nov 2022 10:36:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90AD6802C16; Tue, 15 Nov 2022 15:36:45 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id D49222166B2B; Tue, 15 Nov 2022 15:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526610; 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=G+CMx7bhHy1RPM7Isd3Dgm8HDohp+a70XZsFhHXa7dk=; b=CTceQxQmte3XD9B686pzY7gfVexNSrSl5yPEgstTOEbNJ6Mk+HsVfAPGs+Z6N8JKrQFmKg kDE58kxs5qA+MGQNnMhEEg+XLePQR2EeTiIYYJRHFrovkD4WC7Ndj3J87fMgWEbpVU9EGD d2otKdHgO6FHp/6JdxWXeokrRkbbynY= X-MC-Unique: Ie1gEk3UPp6WSAC9Fn_Bmw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 27/30] migration: Send requested page directly in rp-return thread Date: Tue, 15 Nov 2022 16:35:11 +0100 Message-Id: <20221115153514.28003-28-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URG_BIZ=0.573 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527956325100003 Content-Type: text/plain; charset="utf-8" From: Peter Xu With all the facilities ready, send the requested page directly in the rp-return thread rather than queuing it in the request queue, if and only if postcopy preempt is enabled. It can achieve so because it uses separate channel for sending urgent pages. The only shared data is bitmap and it's protected by the bitmap_mutex. Note that since we're moving the ownership of the urgent channel from the migration thread to rp thread it also means the rp thread is responsible for managing the qemufile, e.g. properly close it when pausing migration happens. For this, let migration_release_from_dst_file to cover shutdown of the urgent channel too, renaming it as migration_release_dst_files() to better show what it does. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.c | 35 +++++++------ migration/ram.c | 112 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 16 deletions(-) diff --git a/migration/migration.c b/migration/migration.c index 1f95877fb4..42f36c1e2c 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2868,8 +2868,11 @@ static int migrate_handle_rp_resume_ack(MigrationSta= te *s, uint32_t value) return 0; } =20 -/* Release ms->rp_state.from_dst_file in a safe way */ -static void migration_release_from_dst_file(MigrationState *ms) +/* + * Release ms->rp_state.from_dst_file (and postcopy_qemufile_src if + * existed) in a safe way. + */ +static void migration_release_dst_files(MigrationState *ms) { QEMUFile *file; =20 @@ -2882,6 +2885,18 @@ static void migration_release_from_dst_file(Migratio= nState *ms) ms->rp_state.from_dst_file =3D NULL; } =20 + /* + * Do the same to postcopy fast path socket too if there is. No + * locking needed because this qemufile should only be managed by + * return path thread. + */ + if (ms->postcopy_qemufile_src) { + migration_ioc_unregister_yank_from_file(ms->postcopy_qemufile_src); + qemu_file_shutdown(ms->postcopy_qemufile_src); + qemu_fclose(ms->postcopy_qemufile_src); + ms->postcopy_qemufile_src =3D NULL; + } + qemu_fclose(file); } =20 @@ -3026,7 +3041,7 @@ out: * Maybe there is something we can do: it looks like a * network down issue, and we pause for a recovery. */ - migration_release_from_dst_file(ms); + migration_release_dst_files(ms); rp =3D NULL; if (postcopy_pause_return_path_thread(ms)) { /* @@ -3044,7 +3059,7 @@ out: } =20 trace_source_return_path_thread_end(); - migration_release_from_dst_file(ms); + migration_release_dst_files(ms); rcu_unregister_thread(); return NULL; } @@ -3567,18 +3582,6 @@ static MigThrError postcopy_pause(MigrationState *s) qemu_file_shutdown(file); qemu_fclose(file); =20 - /* - * Do the same to postcopy fast path socket too if there is. No - * locking needed because no racer as long as we do this before se= tting - * status to paused. - */ - if (s->postcopy_qemufile_src) { - migration_ioc_unregister_yank_from_file(s->postcopy_qemufile_s= rc); - qemu_file_shutdown(s->postcopy_qemufile_src); - qemu_fclose(s->postcopy_qemufile_src); - s->postcopy_qemufile_src =3D NULL; - } - migrate_set_state(&s->state, s->state, MIGRATION_STATUS_POSTCOPY_PAUSED); =20 diff --git a/migration/ram.c b/migration/ram.c index dbdde5a6a5..5dc221a2fc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -574,6 +574,8 @@ static QemuThread *decompress_threads; static QemuMutex decomp_done_lock; static QemuCond decomp_done_cond; =20 +static int ram_save_host_page_urgent(PageSearchStatus *pss); + static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, ram_addr_t offset, uint8_t *source_buf); =20 @@ -588,6 +590,16 @@ static void pss_init(PageSearchStatus *pss, RAMBlock *= rb, ram_addr_t page) pss->complete_round =3D false; } =20 +/* + * Check whether two PSSs are actively sending the same page. Return true + * if it is, false otherwise. + */ +static bool pss_overlap(PageSearchStatus *pss1, PageSearchStatus *pss2) +{ + return pss1->host_page_sending && pss2->host_page_sending && + (pss1->host_page_start =3D=3D pss2->host_page_start); +} + static void *do_data_compress(void *opaque) { CompressParam *param =3D opaque; @@ -2288,6 +2300,57 @@ int ram_save_queue_pages(const char *rbname, ram_add= r_t start, ram_addr_t len) return -1; } =20 + /* + * When with postcopy preempt, we send back the page directly in the + * rp-return thread. + */ + if (postcopy_preempt_active()) { + ram_addr_t page_start =3D start >> TARGET_PAGE_BITS; + size_t page_size =3D qemu_ram_pagesize(ramblock); + PageSearchStatus *pss =3D &ram_state->pss[RAM_CHANNEL_POSTCOPY]; + int ret =3D 0; + + qemu_mutex_lock(&rs->bitmap_mutex); + + pss_init(pss, ramblock, page_start); + /* + * Always use the preempt channel, and make sure it's there. It's + * safe to access without lock, because when rp-thread is running + * we should be the only one who operates on the qemufile + */ + pss->pss_channel =3D migrate_get_current()->postcopy_qemufile_src; + pss->postcopy_requested =3D true; + assert(pss->pss_channel); + + /* + * It must be either one or multiple of host page size. Just + * assert; if something wrong we're mostly split brain anyway. + */ + assert(len % page_size =3D=3D 0); + while (len) { + if (ram_save_host_page_urgent(pss)) { + error_report("%s: ram_save_host_page_urgent() failed: " + "ramblock=3D%s, start_addr=3D0x"RAM_ADDR_FMT, + __func__, ramblock->idstr, start); + ret =3D -1; + break; + } + /* + * NOTE: after ram_save_host_page_urgent() succeeded, pss->page + * will automatically be moved and point to the next host page + * we're going to send, so no need to update here. + * + * Normally QEMU never sends >1 host page in requests, so + * logically we don't even need that as the loop should only + * run once, but just to be consistent. + */ + len -=3D page_size; + }; + qemu_mutex_unlock(&rs->bitmap_mutex); + + return ret; + } + struct RAMSrcPageRequest *new_entry =3D g_new0(struct RAMSrcPageRequest, 1); new_entry->rb =3D ramblock; @@ -2565,6 +2628,55 @@ static void pss_host_page_finish(PageSearchStatus *p= ss) pss->host_page_start =3D pss->host_page_end =3D 0; } =20 +/* + * Send an urgent host page specified by `pss'. Need to be called with + * bitmap_mutex held. + * + * Returns 0 if save host page succeeded, false otherwise. + */ +static int ram_save_host_page_urgent(PageSearchStatus *pss) +{ + bool page_dirty, sent =3D false; + RAMState *rs =3D ram_state; + int ret =3D 0; + + trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); + pss_host_page_prepare(pss); + + /* + * If precopy is sending the same page, let it be done in precopy, or + * we could send the same page in two channels and none of them will + * receive the whole page. + */ + if (pss_overlap(pss, &ram_state->pss[RAM_CHANNEL_PRECOPY])) { + trace_postcopy_preempt_hit(pss->block->idstr, + pss->page << TARGET_PAGE_BITS); + return 0; + } + + do { + page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); + + if (page_dirty) { + /* Be strict to return code; it must be 1, or what else? */ + if (ram_save_target_page(rs, pss) !=3D 1) { + error_report_once("%s: ram_save_target_page failed", __fun= c__); + ret =3D -1; + goto out; + } + sent =3D true; + } + pss_find_next_dirty(pss); + } while (pss_within_range(pss)); +out: + pss_host_page_finish(pss); + /* For urgent requests, flush immediately if sent */ + if (sent) { + qemu_fflush(pss->pss_channel); + } + return ret; +} + /** * ram_save_host_page: save a whole host page * --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527590; cv=none; d=zohomail.com; s=zohoarc; b=gCjXkKN4nHMJc9hzRF9ggOejDruHPhF4WbriCN87ZVlsBTvxfxflSfi9AdCevFAClKPpU0Ouqg3V+JNHT6YeZip4BVRLa9srakhWHbwbz+oyrASFiS9LG61OK086RSuu8SfHX5aiYDE64iRHRQp5awHMYBcvnWZyFksPmU4faHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527590; 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=BCTsrezeXx0dGku5QYWcHR2LbrSSVmETthkRgKnfIgg=; b=I50CfzXVMLGUemESDz69s3lx7bkSUIk8cCk3pJ6QAmyEU8FU1Tgqk6vEAQ/NFdOGACMVe6ItnSG6ZWQ5R1SEdtx9yCuhrv9IO92n5sDnBupO5lMsUAT7OKJPfdZ52n0q8MeeYk+C/lz7mIisQ4ux39DmUOQ+FE9Ipc+s+VtrKXA= 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+importer=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 1668527590722518.6453302119066; Tue, 15 Nov 2022 07:53:10 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzx-0006tk-JA; Tue, 15 Nov 2022 10:37:17 -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 1ouxzn-0006b2-6l for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37:08 -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 1ouxzi-0000Nm-8G for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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-610-esTHpbesODiWjVPqD1tBrA-1; Tue, 15 Nov 2022 10:36:49 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 980472A59550; Tue, 15 Nov 2022 15:36:48 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA7192166B2B; Tue, 15 Nov 2022 15:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526619; 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=BCTsrezeXx0dGku5QYWcHR2LbrSSVmETthkRgKnfIgg=; b=Nd5hKyPqlV6hWAcT/t/XcCpR4sTSz+YVXDgBwaNXBS/ZoeGfDe+eBPQDitjMGIFE9nGywi 6p1pjMoVOBUcDsI8BfZB9ZS0XqMLuyxAthecJzOgkGuh6aAjoAFUzLdqOA0V6w7gba61Xm XTDEWWiYT9Tt/xELjM8QOHMvdUJAoSM= X-MC-Unique: esTHpbesODiWjVPqD1tBrA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 28/30] migration: Remove old preempt code around state maintainance Date: Tue, 15 Nov 2022 16:35:12 +0100 Message-Id: <20221115153514.28003-29-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 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, URG_BIZ=0.573 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527592070100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu With the new code to send pages in rp-return thread, there's little help to keep lots of the old code on maintaining the preempt state in migration thread, because the new way should always be faster.. Then if we'll always send pages in the rp-return thread anyway, we don't need those logic to maintain preempt state anymore because now we serialize things using the mutex directly instead of using those fields. It's very unfortunate to have those code for a short period, but that's still one intermediate step that we noticed the next bottleneck on the migration thread. Now what we can do best is to drop unnecessary code as long as the new code is stable to reduce the burden. It's actually a good thing because the new "sending page in rp-return thread" model is (IMHO) even cleaner and with better performance. Remove the old code that was responsible for maintaining preempt states, at the meantime also remove x-postcopy-preempt-break-huge parameter because with concurrent sender threads we don't really need to break-huge anymore. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/migration.h | 7 - migration/migration.c | 2 - migration/ram.c | 291 +----------------------------------------- 3 files changed, 3 insertions(+), 297 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index cdad8aceaa..ae4ffd3454 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -340,13 +340,6 @@ struct MigrationState { bool send_configuration; /* Whether we send section footer during migration */ bool send_section_footer; - /* - * Whether we allow break sending huge pages when postcopy preempt is - * enabled. When disabled, we won't interrupt precopy within sending a - * host huge page, which is the old behavior of vanilla postcopy. - * NOTE: this parameter is ignored if postcopy preempt is not enabled. - */ - bool postcopy_preempt_break_huge; =20 /* Needed by postcopy-pause state */ QemuSemaphore postcopy_pause_sem; diff --git a/migration/migration.c b/migration/migration.c index 42f36c1e2c..22fc863c67 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -4422,8 +4422,6 @@ static Property migration_properties[] =3D { DEFINE_PROP_SIZE("announce-step", MigrationState, parameters.announce_step, DEFAULT_MIGRATE_ANNOUNCE_STEP), - DEFINE_PROP_BOOL("x-postcopy-preempt-break-huge", MigrationState, - postcopy_preempt_break_huge, true), DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds), DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_host= name), DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz), diff --git a/migration/ram.c b/migration/ram.c index 5dc221a2fc..88e61b0aeb 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -125,28 +125,6 @@ struct PageSearchStatus { unsigned long page; /* Set once we wrap around */ bool complete_round; - /* - * [POSTCOPY-ONLY] Whether current page is explicitly requested by - * postcopy. When set, the request is "urgent" because the dest QEMU - * threads are waiting for us. - */ - bool postcopy_requested; - /* - * [POSTCOPY-ONLY] The target channel to use to send current page. - * - * Note: This may _not_ match with the value in postcopy_requested - * above. Let's imagine the case where the postcopy request is exactly - * the page that we're sending in progress during precopy. In this case - * we'll have postcopy_requested set to true but the target channel - * will be the precopy channel (so that we don't split brain on that - * specific page since the precopy channel already contains partial of - * that page data). - * - * Besides that specific use case, postcopy_target_channel should - * always be equal to postcopy_requested, because by default we send - * postcopy pages via postcopy preempt channel. - */ - bool postcopy_target_channel; /* Whether we're sending a host page */ bool host_page_sending; /* The start/end of current host page. Invalid if host_page_sending= =3D=3Dfalse */ @@ -371,20 +349,6 @@ struct RAMSrcPageRequest { QSIMPLEQ_ENTRY(RAMSrcPageRequest) next_req; }; =20 -typedef struct { - /* - * Cached ramblock/offset values if preempted. They're only meaningfu= l if - * preempted=3D=3Dtrue below. - */ - RAMBlock *ram_block; - unsigned long ram_page; - /* - * Whether a postcopy preemption just happened. Will be reset after - * precopy recovered to background migration. - */ - bool preempted; -} PostcopyPreemptState; - /* State of RAM for migration */ struct RAMState { /* QEMUFile used for this migration */ @@ -447,14 +411,6 @@ struct RAMState { /* Queue of outstanding page requests from the destination */ QemuMutex src_page_req_mutex; QSIMPLEQ_HEAD(, RAMSrcPageRequest) src_page_requests; - - /* Postcopy preemption informations */ - PostcopyPreemptState postcopy_preempt_state; - /* - * Current channel we're using on src VM. Only valid if postcopy-pree= mpt - * is enabled. - */ - unsigned int postcopy_channel; }; typedef struct RAMState RAMState; =20 @@ -462,11 +418,6 @@ static RAMState *ram_state; =20 static NotifierWithReturnList precopy_notifier_list; =20 -static void postcopy_preempt_reset(RAMState *rs) -{ - memset(&rs->postcopy_preempt_state, 0, sizeof(PostcopyPreemptState)); -} - /* Whether postcopy has queued requests? */ static bool postcopy_has_request(RAMState *rs) { @@ -579,9 +530,6 @@ static int ram_save_host_page_urgent(PageSearchStatus *= pss); static bool do_compress_ram_page(QEMUFile *f, z_stream *stream, RAMBlock *= block, ram_addr_t offset, uint8_t *source_buf); =20 -static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, - bool postcopy_requested); - /* NOTE: page is the PFN not real ram_addr_t. */ static void pss_init(PageSearchStatus *pss, RAMBlock *rb, ram_addr_t page) { @@ -1640,13 +1588,6 @@ retry: */ static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *ag= ain) { - /* - * This is not a postcopy requested page, mark it "not urgent", and use - * precopy channel to send it. - */ - pss->postcopy_requested =3D false; - pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; - /* Update pss->page for the next dirty bit in ramblock */ pss_find_next_dirty(pss); =20 @@ -2097,55 +2038,6 @@ void ram_write_tracking_stop(void) } #endif /* defined(__linux__) */ =20 -/* - * Check whether two addr/offset of the ramblock falls onto the same host = huge - * page. Returns true if so, false otherwise. - */ -static bool offset_on_same_huge_page(RAMBlock *rb, uint64_t addr1, - uint64_t addr2) -{ - size_t page_size =3D qemu_ram_pagesize(rb); - - addr1 =3D ROUND_DOWN(addr1, page_size); - addr2 =3D ROUND_DOWN(addr2, page_size); - - return addr1 =3D=3D addr2; -} - -/* - * Whether a previous preempted precopy huge page contains current request= ed - * page? Returns true if so, false otherwise. - * - * This should really happen very rarely, because it means when we were se= nding - * during background migration for postcopy we're sending exactly the page= that - * some vcpu got faulted on on dest node. When it happens, we probably do= n't - * need to do much but drop the request, because we know right after we re= store - * the precopy stream it'll be serviced. It'll slightly affect the order = of - * postcopy requests to be serviced (e.g. it'll be the same as we move cur= rent - * request to the end of the queue) but it shouldn't be a big deal. The m= ost - * imporant thing is we can _never_ try to send a partial-sent huge page o= n the - * POSTCOPY channel again, otherwise that huge page will got "split brain"= on - * two channels (PRECOPY, POSTCOPY). - */ -static bool postcopy_preempted_contains(RAMState *rs, RAMBlock *block, - ram_addr_t offset) -{ - PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; - - /* No preemption at all? */ - if (!state->preempted) { - return false; - } - - /* Not even the same ramblock? */ - if (state->ram_block !=3D block) { - return false; - } - - return offset_on_same_huge_page(block, offset, - state->ram_page << TARGET_PAGE_BITS); -} - /** * get_queued_page: unqueue a page from the postcopy requests * @@ -2185,20 +2077,7 @@ static bool get_queued_page(RAMState *rs, PageSearch= Status *pss) =20 } while (block && !dirty); =20 - if (block) { - /* See comment above postcopy_preempted_contains() */ - if (postcopy_preempted_contains(rs, block, offset)) { - trace_postcopy_preempt_hit(block->idstr, offset); - /* - * If what we preempted previously was exactly what we're - * requesting right now, restore the preempted precopy - * immediately, boosting its priority as it's requested by - * postcopy. - */ - postcopy_preempt_restore(rs, pss, true); - return true; - } - } else { + if (!block) { /* * Poll write faults too if background snapshot is enabled; that's * when we have vcpus got blocked by the write protected pages. @@ -2220,9 +2099,6 @@ static bool get_queued_page(RAMState *rs, PageSearchS= tatus *pss) * really rare. */ pss->complete_round =3D false; - /* Mark it an urgent request, meanwhile using POSTCOPY channel */ - pss->postcopy_requested =3D true; - pss->postcopy_target_channel =3D RAM_CHANNEL_POSTCOPY; } =20 return !!block; @@ -2319,7 +2195,6 @@ int ram_save_queue_pages(const char *rbname, ram_addr= _t start, ram_addr_t len) * we should be the only one who operates on the qemufile */ pss->pss_channel =3D migrate_get_current()->postcopy_qemufile_src; - pss->postcopy_requested =3D true; assert(pss->pss_channel); =20 /* @@ -2467,129 +2342,6 @@ static int ram_save_target_page(RAMState *rs, PageS= earchStatus *pss) return ram_save_page(rs, pss); } =20 -static bool postcopy_needs_preempt(RAMState *rs, PageSearchStatus *pss) -{ - MigrationState *ms =3D migrate_get_current(); - - /* Not enabled eager preempt? Then never do that. */ - if (!migrate_postcopy_preempt()) { - return false; - } - - /* If the user explicitly disabled breaking of huge page, skip */ - if (!ms->postcopy_preempt_break_huge) { - return false; - } - - /* If the ramblock we're sending is a small page? Never bother. */ - if (qemu_ram_pagesize(pss->block) =3D=3D TARGET_PAGE_SIZE) { - return false; - } - - /* Not in postcopy at all? */ - if (!migration_in_postcopy()) { - return false; - } - - /* - * If we're already handling a postcopy request, don't preempt as this= page - * has got the same high priority. - */ - if (pss->postcopy_requested) { - return false; - } - - /* If there's postcopy requests, then check it up! */ - return postcopy_has_request(rs); -} - -/* Returns true if we preempted precopy, false otherwise */ -static void postcopy_do_preempt(RAMState *rs, PageSearchStatus *pss) -{ - PostcopyPreemptState *p_state =3D &rs->postcopy_preempt_state; - - trace_postcopy_preempt_triggered(pss->block->idstr, pss->page); - - /* - * Time to preempt precopy. Cache current PSS into preempt state, so t= hat - * after handling the postcopy pages we can recover to it. We need to= do - * so because the dest VM will have partial of the precopy huge page k= ept - * over in its tmp huge page caches; better move on with it when we ca= n. - */ - p_state->ram_block =3D pss->block; - p_state->ram_page =3D pss->page; - p_state->preempted =3D true; -} - -/* Whether we're preempted by a postcopy request during sending a huge pag= e */ -static bool postcopy_preempt_triggered(RAMState *rs) -{ - return rs->postcopy_preempt_state.preempted; -} - -static void postcopy_preempt_restore(RAMState *rs, PageSearchStatus *pss, - bool postcopy_requested) -{ - PostcopyPreemptState *state =3D &rs->postcopy_preempt_state; - - assert(state->preempted); - - pss->block =3D state->ram_block; - pss->page =3D state->ram_page; - - /* Whether this is a postcopy request? */ - pss->postcopy_requested =3D postcopy_requested; - /* - * When restoring a preempted page, the old data resides in PRECOPY - * slow channel, even if postcopy_requested is set. So always use - * PRECOPY channel here. - */ - pss->postcopy_target_channel =3D RAM_CHANNEL_PRECOPY; - - trace_postcopy_preempt_restored(pss->block->idstr, pss->page); - - /* Reset preempt state, most importantly, set preempted=3D=3Dfalse */ - postcopy_preempt_reset(rs); -} - -static void postcopy_preempt_choose_channel(RAMState *rs, PageSearchStatus= *pss) -{ - MigrationState *s =3D migrate_get_current(); - unsigned int channel =3D pss->postcopy_target_channel; - QEMUFile *next; - - if (channel !=3D rs->postcopy_channel) { - if (channel =3D=3D RAM_CHANNEL_PRECOPY) { - next =3D s->to_dst_file; - } else { - next =3D s->postcopy_qemufile_src; - } - /* Update and cache the current channel */ - rs->f =3D next; - rs->postcopy_channel =3D channel; - - /* - * If channel switched, reset last_sent_block since the old sent b= lock - * may not be on the same channel. - */ - pss->last_sent_block =3D NULL; - - trace_postcopy_preempt_switch_channel(channel); - } - - trace_postcopy_preempt_send_host_page(pss->block->idstr, pss->page); -} - -/* We need to make sure rs->f always points to the default channel elsewhe= re */ -static void postcopy_preempt_reset_channel(RAMState *rs) -{ - if (postcopy_preempt_active()) { - rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; - rs->f =3D migrate_get_current()->to_dst_file; - trace_postcopy_preempt_reset_channel(); - } -} - /* Should be called before sending a host page */ static void pss_host_page_prepare(PageSearchStatus *pss) { @@ -2716,11 +2468,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) pss_host_page_prepare(pss); =20 do { - if (postcopy_needs_preempt(rs, pss)) { - postcopy_do_preempt(rs, pss); - break; - } - page_dirty =3D migration_bitmap_clear_dirty(rs, pss->block, pss->p= age); =20 /* Check the pages is dirty and if it is send it */ @@ -2761,19 +2508,6 @@ static int ram_save_host_page(RAMState *rs, PageSear= chStatus *pss) =20 pss_host_page_finish(pss); =20 - /* - * When with postcopy preempt mode, flush the data as soon as possible= for - * postcopy requests, because we've already sent a whole huge page, so= the - * dst node should already have enough resource to atomically filling = in - * the current missing page. - * - * More importantly, when using separate postcopy channel, we must do - * explicit flush or it won't flush until the buffer is full. - */ - if (migrate_postcopy_preempt() && pss->postcopy_requested) { - qemu_fflush(pss->pss_channel); - } - res =3D ram_save_release_protection(rs, pss, start_page); return (res < 0 ? res : pages); } @@ -2821,24 +2555,11 @@ static int ram_find_and_save_block(RAMState *rs) found =3D get_queued_page(rs, pss); =20 if (!found) { - /* - * Recover previous precopy ramblock/offset if postcopy has - * preempted precopy. Otherwise find the next dirty bit. - */ - if (postcopy_preempt_triggered(rs)) { - postcopy_preempt_restore(rs, pss, false); - found =3D true; - } else { - /* priority queue empty, so just search for something dirt= y */ - found =3D find_dirty_block(rs, pss, &again); - } + /* priority queue empty, so just search for something dirty */ + found =3D find_dirty_block(rs, pss, &again); } =20 if (found) { - /* Update rs->f with correct channel */ - if (postcopy_preempt_active()) { - postcopy_preempt_choose_channel(rs, pss); - } /* Cache rs->f in pss_channel (TODO: remove rs->f) */ pss->pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, pss); @@ -2970,8 +2691,6 @@ static void ram_state_reset(RAMState *rs) rs->last_page =3D 0; rs->last_version =3D ram_list.version; rs->xbzrle_enabled =3D false; - postcopy_preempt_reset(rs); - rs->postcopy_channel =3D RAM_CHANNEL_PRECOPY; } =20 #define MAX_WAIT 50 /* ms, half buffered_file limit */ @@ -3615,8 +3334,6 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } qemu_mutex_unlock(&rs->bitmap_mutex); =20 - postcopy_preempt_reset_channel(rs); - /* * Must occur before EOS (or any QEMUFile operation) * because of RDMA protocol. @@ -3696,8 +3413,6 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return ret; } =20 - postcopy_preempt_reset_channel(rs); - ret =3D multifd_send_sync_main(rs->f); if (ret < 0) { return ret; --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668526776; cv=none; d=zohomail.com; s=zohoarc; b=StV/4dnfWg7cU3q9026lwyBy6ZMLEDIgJ4EXtF/qG7EfZvdkcvBtt6FnibyJ/x/Eu96zBfG8ssz6j+q3COe3oaZOwwZwbMB6Spf+IkHM2Q5dC3gyFdtgmjSf+npD8kd7a+mjiPhvZ45bwugOHqSyAOxxKMuBhPr+W9bP497rxyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668526776; 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=VYCaAlY9TAGcGYJDBiGWmUeI/l8eOnSvx8conJALnKU=; b=n1YKv39CL7FbvxkeaJ+xvNX6lJrisOGbryFMi/YqaAnCNhd3AYG5BpTm5CwL0xpzrWKWfjDzntKAXB0ZLp5SCgWzhhuXj3hQ2liWmCxVHSS71pBHDkN67pCfpKx8Gg/d6bClHq5rPhPRitnTy7RrFlPVfYsfx5ozzklspEdCeOg= 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+importer=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 1668526776551583.5695370734991; Tue, 15 Nov 2022 07:39:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzy-0006wP-U7; Tue, 15 Nov 2022 10:37:18 -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 1ouxzj-0006a3-Vb for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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 1ouxzd-0000Mv-KH for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37:00 -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-155-8aT-yC5oPQeze9gCuFZ4QA-1; Tue, 15 Nov 2022 10:36:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 916CA185A792; Tue, 15 Nov 2022 15:36:51 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id E11712166B2B; Tue, 15 Nov 2022 15:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526615; 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=VYCaAlY9TAGcGYJDBiGWmUeI/l8eOnSvx8conJALnKU=; b=Ki3DSl3wkDX+U54LTf49RZkU3aRBuylAoTPe81kchqjVaV5CAto4VqSykLNrzPvTADW6L7 5rPGRgFbw5Xf4ZAFGIMFebj85oCJAnsLhmKgIfqdeK/dEvwZqzAkjJTYRt47WfUCU+bCCf Ihq0HdsHPB8yPMfiujh6dx4JQv5i2XE= X-MC-Unique: 8aT-yC5oPQeze9gCuFZ4QA-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 29/30] migration: Drop rs->f Date: Tue, 15 Nov 2022 16:35:13 +0100 Message-Id: <20221115153514.28003-30-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668526777610100001 Content-Type: text/plain; charset="utf-8" From: Peter Xu Now with rs->pss we can already cache channels in pss->pss_channels. That pss_channel contains more infromation than rs->f because it's per-channel. So rs->f could be replaced by rss->pss[RAM_CHANNEL_PRECOPY].pss_channel, while rs->f itself is a bit vague now. Note that vanilla postcopy still send pages via pss[RAM_CHANNEL_PRECOPY], that's slightly confusing but it reflects the reality. Then, after the replacement we can safely drop rs->f. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Peter Xu Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 88e61b0aeb..29e413b97b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -351,8 +351,6 @@ struct RAMSrcPageRequest { =20 /* State of RAM for migration */ struct RAMState { - /* QEMUFile used for this migration */ - QEMUFile *f; /* * PageSearchStatus structures for the channels when send pages. * Protected by the bitmap_mutex. @@ -2560,8 +2558,6 @@ static int ram_find_and_save_block(RAMState *rs) } =20 if (found) { - /* Cache rs->f in pss_channel (TODO: remove rs->f) */ - pss->pss_channel =3D rs->f; pages =3D ram_save_host_page(rs, pss); } } while (!pages && again); @@ -3117,7 +3113,7 @@ static void ram_state_resume_prepare(RAMState *rs, QE= MUFile *out) ram_state_reset(rs); =20 /* Update RAMState cache of output QEMUFile */ - rs->f =3D out; + rs->pss[RAM_CHANNEL_PRECOPY].pss_channel =3D out; =20 trace_ram_state_resume_prepare(pages); } @@ -3208,7 +3204,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) return -1; } } - (*rsp)->f =3D f; + (*rsp)->pss[RAM_CHANNEL_PRECOPY].pss_channel =3D f; =20 WITH_RCU_READ_LOCK_GUARD() { qemu_put_be64(f, ram_bytes_total_common(true) | RAM_SAVE_FLAG_MEM_= SIZE); @@ -3343,7 +3339,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - ret =3D multifd_send_sync_main(rs->f); + ret =3D multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].pss_ch= annel); if (ret < 0) { return ret; } @@ -3413,7 +3409,7 @@ static int ram_save_complete(QEMUFile *f, void *opaqu= e) return ret; } =20 - ret =3D multifd_send_sync_main(rs->f); + ret =3D multifd_send_sync_main(rs->pss[RAM_CHANNEL_PRECOPY].pss_channe= l); if (ret < 0) { return ret; } --=20 2.38.1 From nobody Sat May 11 08:40:44 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668527133; cv=none; d=zohomail.com; s=zohoarc; b=T2ayxduydrtuAhawB2M3WC2U0bxPGShJYYhVz3TXRuNbbNB/h/ygSIKcU12lSWoAhd8l8tjgQvVzWjaxGW+gdqp6ixv/fxJgW8RAyaGjTJnCtjvBBuYTqdNJZ6u59898qjJz+ob1jv3hU8/Jkh76BMQi1mZNiS/qoGnxubEeurA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668527133; 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=shYvfY1m4aFGTKlg3Ec60OJ8M+Vs1dd+K/kBHRLF7PM=; b=G08D1a/4MDyqa67Gli59UUDFyhX4WjKXWVQZIlymabe3qakyeifGSQt5lwG3BIJCGyEoK6YsCy5hwXwxWuTNvftjVy/9mSO8hVwjD+pqtTqOzaHl7ueskBWXOJviibauyny/k81uKWxroCS368leWZnCfi/YskQYq2trAmZRt3k= 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+importer=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 1668527133218232.74351677501352; Tue, 15 Nov 2022 07:45:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ouxzw-0006r8-NG; Tue, 15 Nov 2022 10:37:16 -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 1ouxzn-0006aj-1n for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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 1ouxzf-0000NY-L2 for qemu-devel@nongnu.org; Tue, 15 Nov 2022 10:37: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-451-onBYmOvePEeY8T-9yrgpEw-1; Tue, 15 Nov 2022 10:36:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 658F8811E75; Tue, 15 Nov 2022 15:36:54 +0000 (UTC) Received: from secure.mitica (unknown [10.39.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id D99982166B2B; Tue, 15 Nov 2022 15:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668526619; 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=shYvfY1m4aFGTKlg3Ec60OJ8M+Vs1dd+K/kBHRLF7PM=; b=aYoFRRjG/+lp+/aGWL/dFw1rJeZl3aZ/yIHbN6LuF5/Pro7y/1gIDVQuWNT/fWscMdSsrk RYwJa9RwzY7sadLrYxwWnsDAJhh0n2VX+OVMSGoI/VMjx3aVPp3nDzzpuWxylitKmUKRnT 1ycd1hY9KhIzPNm9odTBhQjsKj0MdF4= X-MC-Unique: onBYmOvePEeY8T-9yrgpEw-1 From: Juan Quintela To: qemu-devel@nongnu.org Cc: Michael Tokarev , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Hildenbrand , Laurent Vivier , Juan Quintela , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Peter Xu , Stefan Hajnoczi , "Dr. David Alan Gilbert" , Thomas Huth , qemu-block@nongnu.org, qemu-trivial@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fam Zheng Subject: [PULL 30/30] migration: Block migration comment or code is wrong Date: Tue, 15 Nov 2022 16:35:14 +0100 Message-Id: <20221115153514.28003-31-quintela@redhat.com> In-Reply-To: <20221115153514.28003-1-quintela@redhat.com> References: <20221115153514.28003-1-quintela@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=quintela@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668527133503100001 Content-Type: text/plain; charset="utf-8" And it appears that what is wrong is the code. During bulk stage we need to make sure that some block is dirty, but no games with max_size at all. Signed-off-by: Juan Quintela Reviewed-by: Stefan Hajnoczi --- migration/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migration/block.c b/migration/block.c index 3577c815a9..4347da1526 100644 --- a/migration/block.c +++ b/migration/block.c @@ -880,8 +880,8 @@ static void block_save_pending(QEMUFile *f, void *opaqu= e, uint64_t max_size, blk_mig_unlock(); =20 /* Report at least one block pending during bulk phase */ - if (pending <=3D max_size && !block_mig_state.bulk_completed) { - pending =3D max_size + BLK_MIG_BLOCK_SIZE; + if (!pending && !block_mig_state.bulk_completed) { + pending =3D BLK_MIG_BLOCK_SIZE; } =20 trace_migration_block_save_pending(pending); --=20 2.38.1