From nobody Tue Feb 10 00:40:05 2026 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=1650923824; cv=none; d=zohomail.com; s=zohoarc; b=aeJbpP77o/GCgkAuP/9xIlKoPasNcgmOOx1EYXbwnN2gHQ8o0lZ9RRzBvPxgiQ9HanTl4MzS+KBLMsigsttc4LlUltRK/mywWK5LKO+/sdX6EMh5oXSknQM51uAS+hGpAw33FyS0s3Q39SD7vnl/GE2XA+QQS/D7B5YfEB3+ck0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650923824; 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=Qb6tF6CJQjonKv1oVyihDvSgZidXotakUOfZADwTqiE=; b=aeLqwgtS5I6EaI4wmL8KvzT6yWnn7aspOcZxN2w8eAIBvT+cIZS60nJZyI5cXICJcy9PObgbtjM7p7Wz4KtZlWaLRVSGVvltSgys7jwrSnHy5r/ErJOFa4h6tXdRiUSIPlgi/BZfwoCJA1R/uGgdwxgKYqrugoq1xA+NkScp0ls= 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 1650923824180625.0835034342923; Mon, 25 Apr 2022 14:57:04 -0700 (PDT) Received: from localhost ([::1]:60794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nj6hb-0006gl-84 for importer@patchew.org; Mon, 25 Apr 2022 17:57:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj6cn-00064u-5V for qemu-devel@nongnu.org; Mon, 25 Apr 2022 17:52:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41880) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nj6cl-000175-4K for qemu-devel@nongnu.org; Mon, 25 Apr 2022 17:52:04 -0400 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-DR5Bk8cFMD6pG4gsh74qdw-1; Mon, 25 Apr 2022 17:52:01 -0400 Received: by mail-oi1-f200.google.com with SMTP id f2-20020aca3802000000b0032303e77135so5061152oia.2 for ; Mon, 25 Apr 2022 14:52:01 -0700 (PDT) Received: from LeoBras.redhat.com ([2804:431:c7f0:2ba0:92e8:26c9:ce7e:f03e]) by smtp.gmail.com with ESMTPSA id q7-20020a056870e60700b000e686d13878sm156807oag.18.2022.04.25.14.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 14:51:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650923522; 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=Qb6tF6CJQjonKv1oVyihDvSgZidXotakUOfZADwTqiE=; b=LLF55KoQolC9eeQVeui9FrUJjX/GoU16+nHYzsTgqYjqpF13HjJxC22fvXNRXHGfGOeZfM ImHRcNqQ6Mq3kfsPwasHOU4ihwADV6Or3f6dtKeUSgv2P9POgFIJk8An9CjenUjUzLMPHr 1kK2tYdw4i6Lv35gbd/txS8+G6WHKrc= X-MC-Unique: DR5Bk8cFMD6pG4gsh74qdw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qb6tF6CJQjonKv1oVyihDvSgZidXotakUOfZADwTqiE=; b=nguDQn6JIOqR+7bem3ft369nI6AcOV5nYqT3TATPKggJmpsUfXyAJcXEvEw+JckfOF eYRGt1+lXZnlQiRoRy9sJ2DzPEqthyZtH4Fz4VMVydP0E/IlDzo/15JAOmYJnc0hjrfX SBm2H6Pm3OArBCdavUxKcevf9VEhFWjL4TPzUy4oOrMCFAs9EgqD9ZAS4PJAKizrcjZw no8/fwbthj87xodegrCTyx5Dm+ymmJAZ4B3mJj8XHm9yD4f48PGChVjcTECwBh1RFD+S ZstgskaqWvShd4yLoyNdAEeDUDiY92a/+5maAF0eTyPPMoDpGhVX7SMMWMdhswHykHFr cEGA== X-Gm-Message-State: AOAM530VzjEhvoJYwsJ2jT3KUriXKtAkhGt6p3op5hPx3FTYQ7ghCsCs 4pTE3kqw8AUyZSlf5fAEgg+eAUeusMmG1iqnJ1RYSQRjnyDjmg+x+DoERUVBASWIskRhtYhuNLM yViG/wiQ5nfxnNA0= X-Received: by 2002:a05:6870:15d3:b0:e5:bae5:4db with SMTP id k19-20020a05687015d300b000e5bae504dbmr12307640oad.245.1650923520379; Mon, 25 Apr 2022 14:52:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySMZDNszJ3W99uhJa1xpaleIH+A4RDFW1jCK8CNx4HCawMJIqJAOnUPBmXseI9OzT7W+e2mA== X-Received: by 2002:a05:6870:15d3:b0:e5:bae5:4db with SMTP id k19-20020a05687015d300b000e5bae504dbmr12307629oad.245.1650923520198; Mon, 25 Apr 2022 14:52:00 -0700 (PDT) From: Leonardo Bras To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini , Elena Ufimtseva , Jagannathan Raman , John G Johnson , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Juan Quintela , "Dr. David Alan Gilbert" , Eric Blake , Markus Armbruster , Fam Zheng , Peter Xu Subject: [PATCH v9 7/7] multifd: Implement zero copy write in multifd migration (multifd-zero-copy) Date: Mon, 25 Apr 2022 18:50:56 -0300 Message-Id: <20220425215055.611825-8-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220425215055.611825-1-leobras@redhat.com> References: <20220425215055.611825-1-leobras@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=leobras@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1650923825308100001 Content-Type: text/plain; charset="utf-8" Implement zero copy send on nocomp_send_write(), by making use of QIOChannel writev + flags & flush interface. Change multifd_send_sync_main() so flush_zero_copy() can be called after each iteration in order to make sure all dirty pages are sent before a new iteration is started. It will also flush at the beginning and at the end of migration. Also make it return -1 if flush_zero_copy() fails, in order to cancel the migration process, and avoid resuming the guest in the target host without receiving all current RAM. This will work fine on RAM migration because the RAM pages are not usually = freed, and there is no problem on changing the pages content between writev_zero_c= opy() and the actual sending of the buffer, because this change will dirty the page a= nd cause it to be re-sent on a next iteration anyway. A lot of locked memory may be needed in order to use multifd migration with zero-copy enabled, so disabling the feature should be necessary for low-privileged users trying to perform multifd migrations. Signed-off-by: Leonardo Bras --- migration/multifd.h | 2 ++ migration/migration.c | 11 ++++++++++- migration/multifd.c | 34 ++++++++++++++++++++++++++++++---- migration/socket.c | 5 +++-- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index bcf5992945..4d8d89e5e5 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -92,6 +92,8 @@ typedef struct { uint32_t packet_len; /* pointer to the packet */ MultiFDPacket_t *packet; + /* multifd flags for sending ram */ + int write_flags; /* multifd flags for each packet */ uint32_t flags; /* size of the next packet that contains pages */ diff --git a/migration/migration.c b/migration/migration.c index 4b6df2eb5e..31739b2af9 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -1497,7 +1497,16 @@ static bool migrate_params_check(MigrationParameters= *params, Error **errp) error_prepend(errp, "Invalid mapping given for block-bitmap-mappin= g: "); return false; } - +#ifdef CONFIG_LINUX + if (params->zero_copy_send && + (!migrate_use_multifd() || + params->multifd_compression !=3D MULTIFD_COMPRESSION_NONE || + (params->tls_creds && *params->tls_creds))) { + error_setg(errp, + "Zero copy only available for non-compressed non-TLS mu= ltifd migration"); + return false; + } +#endif return true; } =20 diff --git a/migration/multifd.c b/migration/multifd.c index 6c940aaa98..e37cc6e0d9 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -569,6 +569,7 @@ void multifd_save_cleanup(void) int multifd_send_sync_main(QEMUFile *f) { int i; + bool flush_zero_copy; =20 if (!migrate_use_multifd()) { return 0; @@ -579,6 +580,14 @@ int multifd_send_sync_main(QEMUFile *f) return -1; } } + + /* + * When using zero-copy, it's necessary to flush after each iteration = to + * make sure pages from earlier iterations don't end up replacing newer + * pages. + */ + flush_zero_copy =3D migrate_use_zero_copy_send(); + for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; =20 @@ -600,6 +609,17 @@ int multifd_send_sync_main(QEMUFile *f) ram_counters.transferred +=3D p->packet_len; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); + + 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; + } + } } for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; @@ -688,10 +708,9 @@ static void *multifd_send_thread(void *opaque) p->iov[0].iov_base =3D p->packet; } =20 - ret =3D qio_channel_writev_all(p->c, p->iov + iov_offset, - p->iovs_num - iov_offset, - &local_err); - + ret =3D qio_channel_writev_full_all(p->c, p->iov + iov_offset, + p->iovs_num - iov_offset, NU= LL, + 0, p->write_flags, &local_er= r); if (ret !=3D 0) { break; } @@ -920,6 +939,13 @@ 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); + + if (migrate_use_zero_copy_send()) { + p->write_flags =3D QIO_CHANNEL_WRITE_FLAG_ZERO_COPY; + } else { + p->write_flags =3D 0; + } + socket_send_channel_create(multifd_new_send_channel_async, p); } =20 diff --git a/migration/socket.c b/migration/socket.c index 3754d8f72c..4fd5e85f50 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -79,8 +79,9 @@ static void socket_outgoing_migration(QIOTask *task, =20 trace_migration_socket_outgoing_connected(data->hostname); =20 - if (migrate_use_zero_copy_send()) { - error_setg(&err, "Zero copy send not available in migration"); + if (migrate_use_zero_copy_send() && + !qio_channel_has_feature(sioc, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY= )) { + error_setg(&err, "Zero copy send feature not detected in host kern= el"); } =20 out: --=20 2.36.0