From nobody Sun May 19 08:26:10 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=1651888797; cv=none; d=zohomail.com; s=zohoarc; b=lOzgkTMxeyb28jEKukRGXNtUj+GKIpZYtuv0pUDyiSvIBgh7s2KJw0vt8cRKYLH4Sa/gO/BDo5bbZIXFISxzzLJ0dYk+CthPBP8rRJlV8pE50SLJVXCvxoMjw22fVPsTPlKX3vHl5nZDP/0EpeG1Ew/i7c1pT4PC2O3fW+PgaHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651888797; 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=gWg6c+Xq8yoFcxO44dKKZ2rZxc9bttWYzIMWPmETgAQ=; b=Fp4YEctfOj96VKK0LHPNwtfLFbPXNJsNHvDjdK1HZN11mGK3yU7luSnyTC5sxLJ4g56jpIXy/4gYpRnHE3HYPTfmYECNBf5xL5DDdJkD6N0Fr8EMgDkyxAd3I98XJvts9tDu3L1352uEi0QzI/S88gNKbonCbtPhXKXsZ2EpbuY= 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 1651888797840308.4647514256757; Fri, 6 May 2022 18:59:57 -0700 (PDT) Received: from localhost ([::1]:47012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9jg-0007vM-DK for importer@patchew.org; Fri, 06 May 2022 21:59:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iM-00058D-8s for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:55974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iK-0006hE-3j for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:33 -0400 Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-497-_GIuJPn6NiG1K5ZzF0HLMA-1; Fri, 06 May 2022 21:58:30 -0400 Received: by mail-oo1-f72.google.com with SMTP id g4-20020a4aa704000000b0035e9501e43dso4556557oom.18 for ; Fri, 06 May 2022 18:58:30 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888711; 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=gWg6c+Xq8yoFcxO44dKKZ2rZxc9bttWYzIMWPmETgAQ=; b=e57QuKRTjpBgY2VFuIex30Mhq7jG5QfHxUe86oOf4yQ9GhroD+WU3K7I7MVnXhCifT9mFx ydapuGjqfGLfqMv9PP4JfIpwlc6rrjqKU9pVE9rEFFGOGIsfXvJ1n86ciIUbi07qh514im 1G/7ZsAza6+ZBPCROQnMdVcktAAIwdM= X-MC-Unique: _GIuJPn6NiG1K5ZzF0HLMA-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=gWg6c+Xq8yoFcxO44dKKZ2rZxc9bttWYzIMWPmETgAQ=; b=ULuenJc9hXgKEmB5WxgOf37JkgD3JIIyMtCdwloNlKBmEB+aE0/KaG1dCphva/lj0L D9aJ5IzKBmH2wbXVcMXe1IZx74/OVHXzJc8HEdo0RcWPD6GOFSl2PNSMj9lVtPx49bok /HUeiFtL6ZDVazsxkbsv5nVwyMvqTq1nf6xCkEwDWOI9cMjbLHWwF4aa7HaNh8450+ER R5971hNxy0DlnwSbwqWnxuh5ZkUJaabPXzUOIfaKS9ESvEW6OCS53o8rqzUMUR9sfn8P Z2NLAmDkl6vSq4/1AIOhaKFMhBd2Af5ij7tQbwnV36takCx5YoIsdaf12aDdbU7WjokX lzbA== X-Gm-Message-State: AOAM53389PQWmWU//KzTIaCHC5NRVEbfOXbE2CEHSixiif2VvofMwYVA 9VKI77Lt20mxmuDsAli9HPQrGSi+pXHh5hGtCKy5yVym8AG8kaBIY+xFAqzHfXQDn1SSA5lYiuD QSaSxLTJ0ZpNV0fI= X-Received: by 2002:a05:6870:4287:b0:ee:13cf:c63 with SMTP id y7-20020a056870428700b000ee13cf0c63mr2505057oah.258.1651888708935; Fri, 06 May 2022 18:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy8pcf5/+wdhVBN75vxiHRwc9vEDAnBVoBDnDncftHB6qv8lNqwYMoSzE8KahfNqyOL9DZ+g== X-Received: by 2002:a05:6870:4287:b0:ee:13cf:c63 with SMTP id y7-20020a056870428700b000ee13cf0c63mr2505051oah.258.1651888708690; Fri, 06 May 2022 18:58:28 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 1/7] QIOChannel: Add flags on io_writev and introduce io_flush callback Date: Fri, 6 May 2022 22:57:53 -0300 Message-Id: <20220507015759.840466-2-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651888798798100003 Add flags to io_writev and introduce io_flush as optional callback to QIOChannelClass, allowing the implementation of zero copy writes by subclasses. How to use them: - Write data using qio_channel_writev*(...,QIO_CHANNEL_WRITE_FLAG_ZERO_COPY= ), - Wait write completion with qio_channel_flush(). Notes: As some zero copy write implementations work asynchronously, it's recommended to keep the write buffer untouched until the return of qio_channel_flush(), to avoid the risk of sending an updated buffer instead of the buffer state during write. As io_flush callback is optional, if a subclass does not implement it, then: - io_flush will return 0 without changing anything. Also, some functions like qio_channel_writev_full_all() were adapted to receive a flag parameter. That allows shared code between zero copy and non-zero copy writev, and also an easier implementation on new flags. Signed-off-by: Leonardo Bras Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu Reviewed-by: Juan Quintela --- include/io/channel.h | 38 +++++++++++++++++++++- chardev/char-io.c | 2 +- hw/remote/mpqemu-link.c | 2 +- io/channel-buffer.c | 1 + io/channel-command.c | 1 + io/channel-file.c | 1 + io/channel-socket.c | 2 ++ io/channel-tls.c | 1 + io/channel-websock.c | 1 + io/channel.c | 49 +++++++++++++++++++++++------ migration/rdma.c | 1 + scsi/pr-manager-helper.c | 2 +- tests/unit/test-io-channel-socket.c | 1 + 13 files changed, 88 insertions(+), 14 deletions(-) diff --git a/include/io/channel.h b/include/io/channel.h index 88988979f8..c680ee7480 100644 --- a/include/io/channel.h +++ b/include/io/channel.h @@ -32,12 +32,15 @@ OBJECT_DECLARE_TYPE(QIOChannel, QIOChannelClass, =20 #define QIO_CHANNEL_ERR_BLOCK -2 =20 +#define QIO_CHANNEL_WRITE_FLAG_ZERO_COPY 0x1 + typedef enum QIOChannelFeature QIOChannelFeature; =20 enum QIOChannelFeature { QIO_CHANNEL_FEATURE_FD_PASS, QIO_CHANNEL_FEATURE_SHUTDOWN, QIO_CHANNEL_FEATURE_LISTEN, + QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY, }; =20 =20 @@ -104,6 +107,7 @@ struct QIOChannelClass { size_t niov, int *fds, size_t nfds, + int flags, Error **errp); ssize_t (*io_readv)(QIOChannel *ioc, const struct iovec *iov, @@ -136,6 +140,8 @@ struct QIOChannelClass { IOHandler *io_read, IOHandler *io_write, void *opaque); + int (*io_flush)(QIOChannel *ioc, + Error **errp); }; =20 /* General I/O handling functions */ @@ -228,6 +234,7 @@ ssize_t qio_channel_readv_full(QIOChannel *ioc, * @niov: the length of the @iov array * @fds: an array of file handles to send * @nfds: number of file handles in @fds + * @flags: write flags (QIO_CHANNEL_WRITE_FLAG_*) * @errp: pointer to a NULL-initialized error object * * Write data to the IO channel, reading it from the @@ -260,6 +267,7 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp); =20 /** @@ -837,6 +845,7 @@ int qio_channel_readv_full_all(QIOChannel *ioc, * @niov: the length of the @iov array * @fds: an array of file handles to send * @nfds: number of file handles in @fds + * @flags: write flags (QIO_CHANNEL_WRITE_FLAG_*) * @errp: pointer to a NULL-initialized error object * * @@ -846,6 +855,14 @@ int qio_channel_readv_full_all(QIOChannel *ioc, * to be written, yielding from the current coroutine * if required. * + * If QIO_CHANNEL_WRITE_FLAG_ZERO_COPY is passed in flags, + * instead of waiting for all requested data to be written, + * this function will wait until it's all queued for writing. + * In this case, if the buffer gets changed between queueing and + * sending, the updated buffer will be sent. If this is not a + * desired behavior, it's suggested to call qio_channel_flush() + * before reusing the buffer. + * * Returns: 0 if all bytes were written, or -1 on error */ =20 @@ -853,6 +870,25 @@ int qio_channel_writev_full_all(QIOChannel *ioc, const struct iovec *iov, size_t niov, int *fds, size_t nfds, - Error **errp); + int flags, Error **errp); + +/** + * qio_channel_flush: + * @ioc: the channel object + * @errp: pointer to a NULL-initialized error object + * + * Will block until every packet queued with + * qio_channel_writev_full() + QIO_CHANNEL_WRITE_FLAG_ZERO_COPY + * is sent, or return in case of any error. + * + * If not implemented, acts as a no-op, and returns 0. + * + * Returns -1 if any error is found, + * 1 if every send failed to use zero copy. + * 0 otherwise. + */ + +int qio_channel_flush(QIOChannel *ioc, + Error **errp); =20 #endif /* QIO_CHANNEL_H */ diff --git a/chardev/char-io.c b/chardev/char-io.c index 8ced184160..4451128cba 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -122,7 +122,7 @@ int io_channel_send_full(QIOChannel *ioc, =20 ret =3D qio_channel_writev_full( ioc, &iov, 1, - fds, nfds, NULL); + fds, nfds, 0, NULL); if (ret =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (offset) { return offset; diff --git a/hw/remote/mpqemu-link.c b/hw/remote/mpqemu-link.c index 2a4aa651ca..9bd98e8219 100644 --- a/hw/remote/mpqemu-link.c +++ b/hw/remote/mpqemu-link.c @@ -68,7 +68,7 @@ bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Err= or **errp) } =20 if (!qio_channel_writev_full_all(ioc, send, G_N_ELEMENTS(send), - fds, nfds, errp)) { + fds, nfds, 0, errp)) { ret =3D true; } else { trace_mpqemu_send_io_error(msg->cmd, msg->size, nfds); diff --git a/io/channel-buffer.c b/io/channel-buffer.c index baa4e2b089..bf52011be2 100644 --- a/io/channel-buffer.c +++ b/io/channel-buffer.c @@ -81,6 +81,7 @@ static ssize_t qio_channel_buffer_writev(QIOChannel *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelBuffer *bioc =3D QIO_CHANNEL_BUFFER(ioc); diff --git a/io/channel-command.c b/io/channel-command.c index 4a1f969aaa..9f2f4a1793 100644 --- a/io/channel-command.c +++ b/io/channel-command.c @@ -276,6 +276,7 @@ static ssize_t qio_channel_command_writev(QIOChannel *i= oc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelCommand *cioc =3D QIO_CHANNEL_COMMAND(ioc); diff --git a/io/channel-file.c b/io/channel-file.c index d146ace7db..b67687c2aa 100644 --- a/io/channel-file.c +++ b/io/channel-file.c @@ -114,6 +114,7 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelFile *fioc =3D QIO_CHANNEL_FILE(ioc); diff --git a/io/channel-socket.c b/io/channel-socket.c index e531d7bd2a..05c425abb8 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -524,6 +524,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *io= c, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); @@ -619,6 +620,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *io= c, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); diff --git a/io/channel-tls.c b/io/channel-tls.c index 2ae1b92fc0..4ce890a538 100644 --- a/io/channel-tls.c +++ b/io/channel-tls.c @@ -301,6 +301,7 @@ static ssize_t qio_channel_tls_writev(QIOChannel *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelTLS *tioc =3D QIO_CHANNEL_TLS(ioc); diff --git a/io/channel-websock.c b/io/channel-websock.c index 55145a6a8c..9619906ac3 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -1127,6 +1127,7 @@ static ssize_t qio_channel_websock_writev(QIOChannel = *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelWebsock *wioc =3D QIO_CHANNEL_WEBSOCK(ioc); diff --git a/io/channel.c b/io/channel.c index e8b019dc36..0640941ac5 100644 --- a/io/channel.c +++ b/io/channel.c @@ -72,18 +72,32 @@ ssize_t qio_channel_writev_full(QIOChannel *ioc, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); =20 - if ((fds || nfds) && - !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { + if (fds || nfds) { + if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_FD_PASS)) { + error_setg_errno(errp, EINVAL, + "Channel does not support file descriptor pas= sing"); + return -1; + } + if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { + error_setg_errno(errp, EINVAL, + "Zero Copy does not support file descriptor p= assing"); + return -1; + } + } + + if ((flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) && + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY)= ) { error_setg_errno(errp, EINVAL, - "Channel does not support file descriptor passing= "); + "Requested Zero Copy feature is not available"); return -1; } =20 - return klass->io_writev(ioc, iov, niov, fds, nfds, errp); + return klass->io_writev(ioc, iov, niov, fds, nfds, flags, errp); } =20 =20 @@ -217,14 +231,14 @@ int qio_channel_writev_all(QIOChannel *ioc, size_t niov, Error **errp) { - return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, errp); + return qio_channel_writev_full_all(ioc, iov, niov, NULL, 0, 0, errp); } =20 int qio_channel_writev_full_all(QIOChannel *ioc, const struct iovec *iov, size_t niov, int *fds, size_t nfds, - Error **errp) + int flags, Error **errp) { int ret =3D -1; struct iovec *local_iov =3D g_new(struct iovec, niov); @@ -237,8 +251,10 @@ int qio_channel_writev_full_all(QIOChannel *ioc, =20 while (nlocal_iov > 0) { ssize_t len; - len =3D qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, n= fds, - errp); + + len =3D qio_channel_writev_full(ioc, local_iov, nlocal_iov, fds, + nfds, flags, errp); + if (len =3D=3D QIO_CHANNEL_ERR_BLOCK) { if (qemu_in_coroutine()) { qio_channel_yield(ioc, G_IO_OUT); @@ -277,7 +293,7 @@ ssize_t qio_channel_writev(QIOChannel *ioc, size_t niov, Error **errp) { - return qio_channel_writev_full(ioc, iov, niov, NULL, 0, errp); + return qio_channel_writev_full(ioc, iov, niov, NULL, 0, 0, errp); } =20 =20 @@ -297,7 +313,7 @@ ssize_t qio_channel_write(QIOChannel *ioc, Error **errp) { struct iovec iov =3D { .iov_base =3D (char *)buf, .iov_len =3D buflen = }; - return qio_channel_writev_full(ioc, &iov, 1, NULL, 0, errp); + return qio_channel_writev_full(ioc, &iov, 1, NULL, 0, 0, errp); } =20 =20 @@ -473,6 +489,19 @@ off_t qio_channel_io_seek(QIOChannel *ioc, return klass->io_seek(ioc, offset, whence, errp); } =20 +int qio_channel_flush(QIOChannel *ioc, + Error **errp) +{ + QIOChannelClass *klass =3D QIO_CHANNEL_GET_CLASS(ioc); + + if (!klass->io_flush || + !qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY)= ) { + return 0; + } + + return klass->io_flush(ioc, errp); +} + =20 static void qio_channel_restart_read(void *opaque) { diff --git a/migration/rdma.c b/migration/rdma.c index ef1e65ec36..672d1958a9 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -2840,6 +2840,7 @@ static ssize_t qio_channel_rdma_writev(QIOChannel *io= c, size_t niov, int *fds, size_t nfds, + int flags, Error **errp) { QIOChannelRDMA *rioc =3D QIO_CHANNEL_RDMA(ioc); diff --git a/scsi/pr-manager-helper.c b/scsi/pr-manager-helper.c index 451c7631b7..3be52a98d5 100644 --- a/scsi/pr-manager-helper.c +++ b/scsi/pr-manager-helper.c @@ -77,7 +77,7 @@ static int pr_manager_helper_write(PRManagerHelper *pr_mg= r, iov.iov_base =3D (void *)buf; iov.iov_len =3D sz; n_written =3D qio_channel_writev_full(QIO_CHANNEL(pr_mgr->ioc), &i= ov, 1, - nfds ? &fd : NULL, nfds, errp); + nfds ? &fd : NULL, nfds, 0, er= rp); =20 if (n_written <=3D 0) { assert(n_written !=3D QIO_CHANNEL_ERR_BLOCK); diff --git a/tests/unit/test-io-channel-socket.c b/tests/unit/test-io-chann= el-socket.c index c49eec1f03..6713886d02 100644 --- a/tests/unit/test-io-channel-socket.c +++ b/tests/unit/test-io-channel-socket.c @@ -444,6 +444,7 @@ static void test_io_channel_unix_fd_pass(void) G_N_ELEMENTS(iosend), fdsend, G_N_ELEMENTS(fdsend), + 0, &error_abort); =20 qio_channel_readv_full(dst, --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651889002; cv=none; d=zohomail.com; s=zohoarc; b=ZCnc4BAvj3AlmkInvHKPo0LT/tBlI0a8JXTrncArhUR+aT9Z0reQCrh+Kjjp/Z0mW1s7ajjMPeLHJpGFiwnDqWeNSY3Y7g5WZ/S28+g3By+9KmGYdLjSgYGU/Yr6cm6fsyMyi966PKhoQJkXi7uxIMVHNE90xf4Qgr1yr4C50OI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651889002; 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=9uyXuwOlxJLf3o8B/kD02vex6vMx1GYpu6R7WnXWXsI=; b=nj+a2ym3qfdYcVWfhIWK2VwKkyG6fTeaBoKYHxGRvfymwWnzx07UIMPE/YQ+6rEZHKdJqtNzhV7ECGxTsLmwi4rahcg3B1T9lPTSKKf88gM3b2macrIjwslGhp+/1U4yxXz3fnXRp/1ADND2uKicqb7ActrB3o/FPhVp9t5otEE= 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 1651889002585972.1161804240695; Fri, 6 May 2022 19:03:22 -0700 (PDT) Received: from localhost ([::1]:54694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9mz-0004iN-Gc for importer@patchew.org; Fri, 06 May 2022 22:03:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iP-0005AO-O6 for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:53753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iN-0006hW-Kc for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:37 -0400 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-368-IvxVthaAP9y8yP3pON6g0A-1; Fri, 06 May 2022 21:58:33 -0400 Received: by mail-ot1-f71.google.com with SMTP id d6-20020a9d51c6000000b0060621097166so3587837oth.16 for ; Fri, 06 May 2022 18:58:33 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888715; 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=9uyXuwOlxJLf3o8B/kD02vex6vMx1GYpu6R7WnXWXsI=; b=h9SMSaS97OCHyCnz77L2SpWGpzuw48GeObYr8O/Rmrwymrs4infFrpIhzEB2iDsewiTlvI PjM9VGRrTJ1biNEJYumIbQqnubE/eNPPYGiRo9dNM4UnLfwXRAg1wq3kqVULQp7Xri1FVL LrC6DvK+I1r2uqQI0BfvLoyWs1SLfqY= X-MC-Unique: IvxVthaAP9y8yP3pON6g0A-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=9uyXuwOlxJLf3o8B/kD02vex6vMx1GYpu6R7WnXWXsI=; b=xK6DOubwHb88Zr8GLnZ7piJdcFV15oszqgdH13OXZ7Lh7thrZbWjPisINH4g4pR/MT l7bKJjPFnN7Lg6+l9aqgJDAslyX8JwzaqL5MzeqS8QOr70H9zczkbAdfkFi4jiFRQksn agSoMuvQijXXh72ICPzE392ys257ZUr7KhrSyDai+3UdSRh1rLTCRniNkAXoGd9pyk83 4GxxRefbPwiB1Si3vLCOqi7728ISooKK0MMTf3y93LdEKSG2Z8+F/J+ZbM0kRrumbOKG jWw+GGK/2hC5W8O6/1D0roOlsQ06Vdtm7x8UTfP4NU+1ZVnnUxNGyrsN+W/PX9WbhM9N tcgQ== X-Gm-Message-State: AOAM532rXYuSXZ4pns/LEBAFliKd+No1TyGaENi1XAt6ebMdymMJ1ANM ypED44jTZNVBKCqPy5aaxEDsz5NrxQRTxveRwayI52+6uBiY6ABUBYbdwtdlcDgTaaaFXGeTX3a Tmwb2kpRmPmlbuXE= X-Received: by 2002:a9d:5188:0:b0:605:f135:161c with SMTP id y8-20020a9d5188000000b00605f135161cmr2069584otg.70.1651888713061; Fri, 06 May 2022 18:58:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7DEln4aLquc1pev9Knlcqdktzu9T1xqOSuZLr++vKWF0Z7RFWW2Mng6QBGPWuK24k4m/TEw== X-Received: by 2002:a9d:5188:0:b0:605:f135:161c with SMTP id y8-20020a9d5188000000b00605f135161cmr2069567otg.70.1651888712810; Fri, 06 May 2022 18:58:32 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 2/7] QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX Date: Fri, 6 May 2022 22:57:54 -0300 Message-Id: <20220507015759.840466-3-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651889003781100001 For CONFIG_LINUX, implement the new zero copy flag and the optional callback io_flush on QIOChannelSocket, but enables it only when MSG_ZEROCOPY feature is available in the host kernel, which is checked on qio_channel_socket_connect_sync() qio_channel_socket_flush() was implemented by counting how many times sendmsg(...,MSG_ZEROCOPY) was successfully called, and then reading the socket's error queue, in order to find how many of them finished sending. Flush will loop until those counters are the same, or until some error occu= rs. Notes on using writev() with QIO_CHANNEL_WRITE_FLAG_ZERO_COPY: 1: Buffer - As MSG_ZEROCOPY tells the kernel to use the same user buffer to avoid cop= ying, some caution is necessary to avoid overwriting any buffer before it's sent. If something like this happen, a newer version of the buffer may be sent in= stead. - If this is a problem, it's recommended to call qio_channel_flush() before= freeing or re-using the buffer. 2: Locked memory - When using MSG_ZERCOCOPY, the buffer memory will be locked after queued, = and unlocked after it's sent. - Depending on the size of each buffer, and how often it's sent, it may req= uire a larger amount of locked memory than usually available to non-root user. - If the required amount of locked memory is not available, writev_zero_copy will return an error, which can abort an operation like migration, - Because of this, when an user code wants to add zero copy as a feature, it requires a mechanism to disable it, so it can still be accessible to less privileged users. Signed-off-by: Leonardo Bras Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela --- include/io/channel-socket.h | 2 + io/channel-socket.c | 117 ++++++++++++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h index e747e63514..513c428fe4 100644 --- a/include/io/channel-socket.h +++ b/include/io/channel-socket.h @@ -47,6 +47,8 @@ struct QIOChannelSocket { socklen_t localAddrLen; struct sockaddr_storage remoteAddr; socklen_t remoteAddrLen; + ssize_t zero_copy_queued; + ssize_t zero_copy_sent; }; =20 =20 diff --git a/io/channel-socket.c b/io/channel-socket.c index 05c425abb8..f03a068f25 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -25,9 +25,18 @@ #include "io/channel-watch.h" #include "trace.h" #include "qapi/clone-visitor.h" +#ifdef CONFIG_LINUX +#include +#include + +#if (defined(MSG_ZEROCOPY) && defined(SO_ZEROCOPY)) +#define QEMU_MSG_ZEROCOPY +#endif +#endif =20 #define SOCKET_MAX_FDS 16 =20 + SocketAddress * qio_channel_socket_get_local_address(QIOChannelSocket *ioc, Error **errp) @@ -54,6 +63,8 @@ qio_channel_socket_new(void) =20 sioc =3D QIO_CHANNEL_SOCKET(object_new(TYPE_QIO_CHANNEL_SOCKET)); sioc->fd =3D -1; + sioc->zero_copy_queued =3D 0; + sioc->zero_copy_sent =3D 0; =20 ioc =3D QIO_CHANNEL(sioc); qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN); @@ -153,6 +164,16 @@ int qio_channel_socket_connect_sync(QIOChannelSocket *= ioc, return -1; } =20 +#ifdef QEMU_MSG_ZEROCOPY + int ret, v =3D 1; + ret =3D setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &v, sizeof(v)); + if (ret =3D=3D 0) { + /* Zero copy available on host */ + qio_channel_set_feature(QIO_CHANNEL(ioc), + QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY); + } +#endif + return 0; } =20 @@ -533,6 +554,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *io= c, char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; size_t fdsize =3D sizeof(int) * nfds; struct cmsghdr *cmsg; + int sflags =3D 0; =20 memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); =20 @@ -557,15 +579,31 @@ static ssize_t qio_channel_socket_writev(QIOChannel *= ioc, memcpy(CMSG_DATA(cmsg), fds, fdsize); } =20 +#ifdef QEMU_MSG_ZEROCOPY + if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { + sflags =3D MSG_ZEROCOPY; + } +#endif + retry: - ret =3D sendmsg(sioc->fd, &msg, 0); + ret =3D sendmsg(sioc->fd, &msg, sflags); if (ret <=3D 0) { - if (errno =3D=3D EAGAIN) { + switch (errno) { + case EAGAIN: return QIO_CHANNEL_ERR_BLOCK; - } - if (errno =3D=3D EINTR) { + case EINTR: goto retry; +#ifdef QEMU_MSG_ZEROCOPY + case ENOBUFS: + if (sflags & MSG_ZEROCOPY) { + error_setg_errno(errp, errno, + "Process can't lock enough memory for usi= ng MSG_ZEROCOPY"); + return -1; + } + break; +#endif } + error_setg_errno(errp, errno, "Unable to write to socket"); return -1; @@ -659,6 +697,74 @@ static ssize_t qio_channel_socket_writev(QIOChannel *i= oc, } #endif /* WIN32 */ =20 + +#ifdef QEMU_MSG_ZEROCOPY +static int qio_channel_socket_flush(QIOChannel *ioc, + Error **errp) +{ + QIOChannelSocket *sioc =3D QIO_CHANNEL_SOCKET(ioc); + struct msghdr msg =3D {}; + struct sock_extended_err *serr; + struct cmsghdr *cm; + char control[CMSG_SPACE(sizeof(*serr))]; + int received; + int ret =3D 1; + + msg.msg_control =3D control; + msg.msg_controllen =3D sizeof(control); + memset(control, 0, sizeof(control)); + + while (sioc->zero_copy_sent < sioc->zero_copy_queued) { + received =3D recvmsg(sioc->fd, &msg, MSG_ERRQUEUE); + if (received < 0) { + switch (errno) { + case EAGAIN: + /* Nothing on errqueue, wait until something is available = */ + qio_channel_wait(ioc, G_IO_ERR); + continue; + case EINTR: + continue; + default: + error_setg_errno(errp, errno, + "Unable to read errqueue"); + return -1; + } + } + + cm =3D CMSG_FIRSTHDR(&msg); + if (cm->cmsg_level !=3D SOL_IP && + cm->cmsg_type !=3D IP_RECVERR) { + error_setg_errno(errp, EPROTOTYPE, + "Wrong cmsg in errqueue"); + return -1; + } + + serr =3D (void *) CMSG_DATA(cm); + if (serr->ee_errno !=3D SO_EE_ORIGIN_NONE) { + error_setg_errno(errp, serr->ee_errno, + "Error on socket"); + return -1; + } + if (serr->ee_origin !=3D SO_EE_ORIGIN_ZEROCOPY) { + error_setg_errno(errp, serr->ee_origin, + "Error not from zero copy"); + return -1; + } + + /* No errors, count successfully finished sendmsg()*/ + sioc->zero_copy_sent +=3D serr->ee_data - serr->ee_info + 1; + + /* If any sendmsg() succeeded using zero copy, return 0 at the end= */ + if (serr->ee_code !=3D SO_EE_CODE_ZEROCOPY_COPIED) { + ret =3D 0; + } + } + + return ret; +} + +#endif /* QEMU_MSG_ZEROCOPY */ + static int qio_channel_socket_set_blocking(QIOChannel *ioc, bool enabled, @@ -789,6 +895,9 @@ static void qio_channel_socket_class_init(ObjectClass *= klass, ioc_klass->io_set_delay =3D qio_channel_socket_set_delay; ioc_klass->io_create_watch =3D qio_channel_socket_create_watch; ioc_klass->io_set_aio_fd_handler =3D qio_channel_socket_set_aio_fd_han= dler; +#ifdef QEMU_MSG_ZEROCOPY + ioc_klass->io_flush =3D qio_channel_socket_flush; +#endif } =20 static const TypeInfo qio_channel_socket_info =3D { --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651888844; cv=none; d=zohomail.com; s=zohoarc; b=kMXEQ8XjP+5sRfvZ8x0EGEHHsdHE6iz9BUBmty5eu7LJbtndL2hx+2fm72a2Q6qL5oFYX/C4tWU6pwffXaKaHtjABL2nASsZeeZFUDGFiGpem1F86PtXTO9XuZXb4jCZCJDIoR9GG5G39ktQRbNBqE2AVUof0/1Fa7eWcmZKHoU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651888844; 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=FoiANFaZUsR+19YSs80XA8m23UAw8e0kNwzw/ub0qn0=; b=iQ4zMyV17oCqJpoTah88sfh5HyAnVOWzYY/T2Lce77HJ0NWAAKVtiw8wtJxflT5FlZZphZMZaVzNrHUUTyTA+8ck+z/oYd0ZfMCBpmjsL2OwhJLd7umVe0fq9jYV8UvqwbPq2oRuRd2//M02VkQq+9CO3li1esqAOlGFOBEZMos= 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 1651888844081159.77266702529255; Fri, 6 May 2022 19:00:44 -0700 (PDT) Received: from localhost ([::1]:48336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9kQ-0000Nm-Vh for importer@patchew.org; Fri, 06 May 2022 22:00:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iX-0005IM-4q for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iV-0006ij-8e for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:44 -0400 Received: from mail-oo1-f69.google.com (mail-oo1-f69.google.com [209.85.161.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-510-9UFCCbbsMKeMcRYMKnodeQ-1; Fri, 06 May 2022 21:58:38 -0400 Received: by mail-oo1-f69.google.com with SMTP id n26-20020a4abd1a000000b0035eb0243b06so4562268oop.22 for ; Fri, 06 May 2022 18:58:38 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888722; 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=FoiANFaZUsR+19YSs80XA8m23UAw8e0kNwzw/ub0qn0=; b=ivYz73DUUUiAgOMMqSIXJz0dN50TeyR18jLREIVqPy/9olIVpcSWa1XbXmkUM1xTKk1hX0 hE97fmDqPVmCtqdSwnADG55jQ8qeWvr9ZFHB0REsLyzcbasFFs3Dg0/CD7WVJ2J0JvqxtL Daot/NDmPdVSejCM5HNC3pBZvtH/7UI= X-MC-Unique: 9UFCCbbsMKeMcRYMKnodeQ-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=FoiANFaZUsR+19YSs80XA8m23UAw8e0kNwzw/ub0qn0=; b=Dd5lNBtBjMRCLZC7nPNikZmBaDJenSZybWyXUsOVxlzIjsODzbT+aRyBtMQgImvndF BZ5HuWqX+ZTFR+B1iPQfFWCUMUMG3YNazXa+jMNunl5kJbR6LEugOF4ha/Ei6e8verbY ZhmNuvbXVM2+ciTpNc4L4KTTlnZqkzrU84/A6zoqllwGZYAqqAJWHYkem7UNuDHyzPHk H2g5c81MjmMCgbQJ4FS/42PK0hi8leD6mbebTdP3n0Q/rJGBX2muqJ55+VIz2BNyhfXL gZ/MVZ/hIStmZOIDkdXuT2WhH0KqIzN7dgKIUMcoWA8wYgnbfrdGE1gTWN99TgMvuIOP 0gfA== X-Gm-Message-State: AOAM530nUhutrx5LB/1DOKNbPrs0niCFdetQedYI/XWEPpqItdt+QWV9 zDiB7x9zsM1U8l8TTHqVRzkTNSXHJuLWiFkvKb8wNqpSFs0N5n+hacxQSJrV85PhoFE0G+8/kDc MEimqEwdvdftVR2Q= X-Received: by 2002:a9d:7392:0:b0:606:4524:ada7 with SMTP id j18-20020a9d7392000000b006064524ada7mr2036257otk.281.1651888717314; Fri, 06 May 2022 18:58:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxq9xI5hzNfg3sGk0tIqQKmKo2N3fh4weeVHTZdTg5EXnyKFGUWcW/sHrZeWSBF58MtKE1BcA== X-Received: by 2002:a9d:7392:0:b0:606:4524:ada7 with SMTP id j18-20020a9d7392000000b006064524ada7mr2036249otk.281.1651888717061; Fri, 06 May 2022 18:58:37 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 3/7] migration: Add zero-copy-send parameter for QMP/HMP for Linux Date: Fri, 6 May 2022 22:57:55 -0300 Message-Id: <20220507015759.840466-4-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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=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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651888845168100001 Add property that allows zero-copy migration of memory pages on the sending side, and also includes a helper function migrate_use_zero_copy_send() to check if it's enabled. No code is introduced to actually do the migration, but it allow future implementations to enable/disable this feature. On non-Linux builds this parameter is compiled-out. Signed-off-by: Leonardo Bras Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Juan Quintela Acked-by: Markus Armbruster --- qapi/migration.json | 24 ++++++++++++++++++++++++ migration/migration.h | 5 +++++ migration/migration.c | 32 ++++++++++++++++++++++++++++++++ migration/socket.c | 11 +++++++++-- monitor/hmp-cmds.c | 6 ++++++ roms/skiboot | 2 +- 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/qapi/migration.json b/qapi/migration.json index 409eb086a2..2222f44250 100644 --- a/qapi/migration.json +++ b/qapi/migration.json @@ -741,6 +741,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @zero-copy-send: Controls behavior on sending memory pages on migration. +# When true, enables a zero-copy mechanism for sending +# memory pages, if host supports it. +# Requires that QEMU be permitted to use locked memory +# for guest RAM pages. +# Defaults to false. (Since 7.1) +# # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such # aliases may for example be the corresponding name= s on the @@ -780,6 +787,7 @@ 'xbzrle-cache-size', 'max-postcopy-bandwidth', 'max-cpu-throttle', 'multifd-compression', 'multifd-zlib-level' ,'multifd-zstd-level', + { 'name': 'zero-copy-send', 'if' : 'CONFIG_LINUX'}, 'block-bitmap-mapping' ] } =20 ## @@ -906,6 +914,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @zero-copy-send: Controls behavior on sending memory pages on migration. +# When true, enables a zero-copy mechanism for sending +# memory pages, if host supports it. +# Requires that QEMU be permitted to use locked memory +# for guest RAM pages. +# Defaults to false. (Since 7.1) +# # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such # aliases may for example be the corresponding name= s on the @@ -960,6 +975,7 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', + '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' }, '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } =20 ## @@ -1106,6 +1122,13 @@ # will consume more CPU. # Defaults to 1. (Since 5.0) # +# @zero-copy-send: Controls behavior on sending memory pages on migration. +# When true, enables a zero-copy mechanism for sending +# memory pages, if host supports it. +# Requires that QEMU be permitted to use locked memory +# for guest RAM pages. +# Defaults to false. (Since 7.1) +# # @block-bitmap-mapping: Maps block nodes and bitmaps on them to # aliases for the purpose of dirty bitmap migration= . Such # aliases may for example be the corresponding name= s on the @@ -1158,6 +1181,7 @@ '*multifd-compression': 'MultiFDCompression', '*multifd-zlib-level': 'uint8', '*multifd-zstd-level': 'uint8', + '*zero-copy-send': { 'type': 'bool', 'if': 'CONFIG_LINUX' }, '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ] } } =20 ## diff --git a/migration/migration.h b/migration/migration.h index a863032b71..e8f2941a55 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -375,6 +375,11 @@ MultiFDCompression migrate_multifd_compression(void); int migrate_multifd_zlib_level(void); int migrate_multifd_zstd_level(void); =20 +#ifdef CONFIG_LINUX +bool migrate_use_zero_copy_send(void); +#else +#define migrate_use_zero_copy_send() (false) +#endif int migrate_use_xbzrle(void); uint64_t migrate_xbzrle_cache_size(void); bool migrate_colo_enabled(void); diff --git a/migration/migration.c b/migration/migration.c index 5a31b23bd6..3e91f4b5e2 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -910,6 +910,10 @@ MigrationParameters *qmp_query_migrate_parameters(Erro= r **errp) params->multifd_zlib_level =3D s->parameters.multifd_zlib_level; params->has_multifd_zstd_level =3D true; params->multifd_zstd_level =3D s->parameters.multifd_zstd_level; +#ifdef CONFIG_LINUX + params->has_zero_copy_send =3D true; + params->zero_copy_send =3D s->parameters.zero_copy_send; +#endif params->has_xbzrle_cache_size =3D true; params->xbzrle_cache_size =3D s->parameters.xbzrle_cache_size; params->has_max_postcopy_bandwidth =3D true; @@ -1567,6 +1571,11 @@ static void migrate_params_test_apply(MigrateSetPara= meters *params, if (params->has_multifd_compression) { dest->multifd_compression =3D params->multifd_compression; } +#ifdef CONFIG_LINUX + if (params->has_zero_copy_send) { + dest->zero_copy_send =3D params->zero_copy_send; + } +#endif if (params->has_xbzrle_cache_size) { dest->xbzrle_cache_size =3D params->xbzrle_cache_size; } @@ -1679,6 +1688,11 @@ static void migrate_params_apply(MigrateSetParameter= s *params, Error **errp) if (params->has_multifd_compression) { s->parameters.multifd_compression =3D params->multifd_compression; } +#ifdef CONFIG_LINUX + if (params->has_zero_copy_send) { + s->parameters.zero_copy_send =3D params->zero_copy_send; + } +#endif if (params->has_xbzrle_cache_size) { s->parameters.xbzrle_cache_size =3D params->xbzrle_cache_size; xbzrle_cache_resize(params->xbzrle_cache_size, errp); @@ -2563,6 +2577,17 @@ int migrate_multifd_zstd_level(void) return s->parameters.multifd_zstd_level; } =20 +#ifdef CONFIG_LINUX +bool migrate_use_zero_copy_send(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.zero_copy_send; +} +#endif + int migrate_use_xbzrle(void) { MigrationState *s; @@ -4206,6 +4231,10 @@ static Property migration_properties[] =3D { DEFINE_PROP_UINT8("multifd-zstd-level", MigrationState, parameters.multifd_zstd_level, DEFAULT_MIGRATE_MULTIFD_ZSTD_LEVEL), +#ifdef CONFIG_LINUX + DEFINE_PROP_BOOL("zero_copy_send", MigrationState, + parameters.zero_copy_send, false), +#endif DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState, parameters.xbzrle_cache_size, DEFAULT_MIGRATE_XBZRLE_CACHE_SIZE), @@ -4303,6 +4332,9 @@ static void migration_instance_init(Object *obj) params->has_multifd_compression =3D true; params->has_multifd_zlib_level =3D true; params->has_multifd_zstd_level =3D true; +#ifdef CONFIG_LINUX + params->has_zero_copy_send =3D true; +#endif params->has_xbzrle_cache_size =3D true; params->has_max_postcopy_bandwidth =3D true; params->has_max_cpu_throttle =3D true; diff --git a/migration/socket.c b/migration/socket.c index 05705a32d8..3754d8f72c 100644 --- a/migration/socket.c +++ b/migration/socket.c @@ -74,9 +74,16 @@ static void socket_outgoing_migration(QIOTask *task, =20 if (qio_task_propagate_error(task, &err)) { trace_migration_socket_outgoing_error(error_get_pretty(err)); - } else { - trace_migration_socket_outgoing_connected(data->hostname); + goto out; } + + trace_migration_socket_outgoing_connected(data->hostname); + + if (migrate_use_zero_copy_send()) { + error_setg(&err, "Zero copy send not available in migration"); + } + +out: migration_channel_connect(data->s, sioc, data->hostname, err); object_unref(OBJECT(sioc)); } diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c index 93061a11af..622c783c32 100644 --- a/monitor/hmp-cmds.c +++ b/monitor/hmp-cmds.c @@ -1309,6 +1309,12 @@ void hmp_migrate_set_parameter(Monitor *mon, const Q= Dict *qdict) p->has_multifd_zstd_level =3D true; visit_type_uint8(v, param, &p->multifd_zstd_level, &err); break; +#ifdef CONFIG_LINUX + case MIGRATION_PARAMETER_ZERO_COPY_SEND: + p->has_zero_copy_send =3D true; + visit_type_bool(v, param, &p->zero_copy_send, &err); + break; +#endif case MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE: p->has_xbzrle_cache_size =3D true; if (!visit_type_size(v, param, &cache_size, &err)) { diff --git a/roms/skiboot b/roms/skiboot index 24a7eb3596..820d43c0a7 160000 --- a/roms/skiboot +++ b/roms/skiboot @@ -1 +1 @@ -Subproject commit 24a7eb35966d93455520bc2debdd7954314b638b +Subproject commit 820d43c0a7751e75a8830561f35535dfffd522bd --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651889008; cv=none; d=zohomail.com; s=zohoarc; b=jLMKRdAHMTm/Aa5XX/+Uf4H/AFW+60Pu0xiFMZ38PYhO2jvejIZAK+CZ6hR3dzAul3TTOTVxhNnNryxaEyM5SYj4bJJ4ywSD2q5RxiPp+Cx1YQ0u0O2kN/GVhExVdFpj1ti/cfTDeYLU6uoc25vZsU2u+JTz7lp5NEJln3GIsDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651889008; 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=OCN4rR4bAIHd7dZhYCUf3JnbZmufgbcGPMyBtVIgbmE=; b=js8Lq5MskCTFiqLQ/10N133RojEt7wcvxFUXlxV+PUsF4Ahm5L8OWs3VucgyNR1+8W5656rA26xWrHaaQhdoYVLe0FLYyhZSj0hFWYu91gC4yN2MCUzMSbA+xsTf4cwTPrZX/crNeR5DIDTcybv3Dwc/qiQAvCPjBVFd/olwpW8= 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 1651889008069870.636011291386; Fri, 6 May 2022 19:03:28 -0700 (PDT) Received: from localhost ([::1]:54872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9n5-0004pW-48 for importer@patchew.org; Fri, 06 May 2022 22:03:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iY-0005LJ-4f for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iV-0006ip-Su for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:45 -0400 Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-5-nhKxiHg5NnCbG2R2EOo40A-1; Fri, 06 May 2022 21:58:42 -0400 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-e653506dd0so4273967fac.14 for ; Fri, 06 May 2022 18:58:42 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888723; 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=OCN4rR4bAIHd7dZhYCUf3JnbZmufgbcGPMyBtVIgbmE=; b=gG6jAvnIazb6zKjDjBGtHQGwme5C0VAVvWowuMyWD/uLAzaBawX4oliJd9JcZqFpX99ibm l/vaF5wWr22o0vP4ux2Zk+51XuWtL5qTs2JuWKN9KETZ5uOoHmwjZ6Ttow6w3L8dLkn9ad ZoRmIsS3uGoELFKV8NiKu+lttu3J83U= X-MC-Unique: nhKxiHg5NnCbG2R2EOo40A-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=OCN4rR4bAIHd7dZhYCUf3JnbZmufgbcGPMyBtVIgbmE=; b=LYsDt3WSpmjNzP0HV1WK9D1csoOr1S79H1dtBXOFXkDWTsDrzq3+/2V2eoO2uDp+9p OCqIUdDb/9ze1LecemrAHaaBtQPANFwSDIwFePGgHw/SVuJgUOF4L5oCSagM/rYQLJM/ ZwEdaWbRvkVuo1f02od3FLfTey7q4KTGbjqNglbahlnHCQ9DoXeHthlR/ILH+sHYeF8c 2Ggq8cKbr2ynkRSEQAyNItMZxIh69jRhILbUH+bbEYUIUAvgWl9SqHYqWrOJOz1C38eb 5cmyHJQoxB41fPtNLFQKhh7NpVP0garO1psdOn6j0b3/u3Hd56mSwuiH1WoJ1Ze3Q00y V6vw== X-Gm-Message-State: AOAM530fOtbq7rP8x0zyW31hCqfm9kRtTAx/SAt8xVRJKS5JVXFldYah 31yKeM6c/BjgIAIj/GW9Jh5mklWsl50Ak01dzo1yVR8i5dZecZfVcPu3teV10bt4UZOAWxzaS9l iMFKB/bZOZFz3p48= X-Received: by 2002:a05:6870:ac0e:b0:ed:9a7d:4881 with SMTP id kw14-20020a056870ac0e00b000ed9a7d4881mr2543553oab.178.1651888721398; Fri, 06 May 2022 18:58:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfjr/F6zDC+FvS/mVcR7TuZpxmE4vOjflWlgE1GtKDloaUE/Di9hQ13GLyfpgrcxsPZOQ87Q== X-Received: by 2002:a05:6870:ac0e:b0:ed:9a7d:4881 with SMTP id kw14-20020a056870ac0e00b000ed9a7d4881mr2543552oab.178.1651888721177; Fri, 06 May 2022 18:58:41 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 4/7] migration: Add migrate_use_tls() helper Date: Fri, 6 May 2022 22:57:56 -0300 Message-Id: <20220507015759.840466-5-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.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=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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651889009799100001 A lot of places check parameters.tls_creds in order to evaluate if TLS is in use, and sometimes call migrate_get_current() just for that test. Add new helper function migrate_use_tls() in order to simplify testing for TLS usage. Signed-off-by: Leonardo Bras Reviewed-by: Juan Quintela Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/migration.h | 1 + migration/channel.c | 3 +-- migration/migration.c | 9 +++++++++ migration/multifd.c | 5 +---- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/migration/migration.h b/migration/migration.h index e8f2941a55..485d58b95f 100644 --- a/migration/migration.h +++ b/migration/migration.h @@ -380,6 +380,7 @@ bool migrate_use_zero_copy_send(void); #else #define migrate_use_zero_copy_send() (false) #endif +int migrate_use_tls(void); int migrate_use_xbzrle(void); uint64_t migrate_xbzrle_cache_size(void); bool migrate_colo_enabled(void); diff --git a/migration/channel.c b/migration/channel.c index c6a8dcf1d7..a162d00fea 100644 --- a/migration/channel.c +++ b/migration/channel.c @@ -38,8 +38,7 @@ void migration_channel_process_incoming(QIOChannel *ioc) trace_migration_set_incoming_channel( ioc, object_get_typename(OBJECT(ioc))); =20 - if (s->parameters.tls_creds && - *s->parameters.tls_creds && + if (migrate_use_tls() && !object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { migration_tls_channel_process_incoming(s, ioc, &local_err); diff --git a/migration/migration.c b/migration/migration.c index 3e91f4b5e2..4b6df2eb5e 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -2588,6 +2588,15 @@ bool migrate_use_zero_copy_send(void) } #endif =20 +int migrate_use_tls(void) +{ + MigrationState *s; + + s =3D migrate_get_current(); + + return s->parameters.tls_creds && *s->parameters.tls_creds; +} + int migrate_use_xbzrle(void) { MigrationState *s; diff --git a/migration/multifd.c b/migration/multifd.c index 9ea4f581e2..2a8c8570c3 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -782,15 +782,12 @@ static bool multifd_channel_connect(MultiFDSendParams= *p, QIOChannel *ioc, Error *error) { - MigrationState *s =3D migrate_get_current(); - trace_multifd_set_outgoing_channel( ioc, object_get_typename(OBJECT(ioc)), migrate_get_current()->hostname, error); =20 if (!error) { - if (s->parameters.tls_creds && - *s->parameters.tls_creds && + if (migrate_use_tls() && !object_dynamic_cast(OBJECT(ioc), TYPE_QIO_CHANNEL_TLS)) { multifd_tls_channel_connect(p, ioc, &error); --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651888818; cv=none; d=zohomail.com; s=zohoarc; b=jH0Co5JTNa7jM0U2jWB55h5kl6YxhIUjhRtgD70FDW98xyy+HROlGctGj19RJrE2Z7tUYTs5gO+zjPApkVTUw6lGSHf8soMh1x0EyekBR5RX1n2IMtj7HZy/+i1T5EU/X9iTaFsFvyEAagr6wRY//UYuHvicOaw+9WqMgymv2jM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651888818; 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=OldqSj6ZhjcEWqr35wQqdzeCrylOxSMHkGFbo7CK6Qo=; b=bI1uZB9EOW/7S8TyIGKzgdbDSIX+s7Ki2JgaF2R1VyVpH81EpiRH1P0UqQydXpZtGhMu1km1jJVutmCC1IceOjU2Smnl4D0xCPldgwfQxjZwSRcGn3x26g1hnQgPxC4gy4P6f9gpkhyf1MfYuvVG0R7GB34JnpOHeyVT5AKNJ+A= 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 1651888818832886.7782002593109; Fri, 6 May 2022 19:00:18 -0700 (PDT) Received: from localhost ([::1]:47782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9k1-0008Rk-Kn for importer@patchew.org; Fri, 06 May 2022 22:00:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9id-0005Xl-CF for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:30050) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9ib-0006jW-Lv for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:51 -0400 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-467-Dgqt0A3ANRCZCmcGedQldA-1; Fri, 06 May 2022 21:58:46 -0400 Received: by mail-oi1-f199.google.com with SMTP id r65-20020acada44000000b002f9c653b942so3261562oig.16 for ; Fri, 06 May 2022 18:58:46 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888729; 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=OldqSj6ZhjcEWqr35wQqdzeCrylOxSMHkGFbo7CK6Qo=; b=CYbDJMGeN6Mi6QxrhfBIuimxSX2C74xyHT4sg1Xgl6sqnueSyQ04XOjMnIsgmX3h2udquq +eGL0tNVkPvy5Otyk7YV7j0D1L9ncbXhcoo5SDwb+tXMTUXjW8lnhUPDtQjEz/vcNWxcGn VOib3pcrBdrlp8EihhcmYCu3v655pWI= X-MC-Unique: Dgqt0A3ANRCZCmcGedQldA-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=OldqSj6ZhjcEWqr35wQqdzeCrylOxSMHkGFbo7CK6Qo=; b=uUW2fSqf+ZFoU2e8LnAWGja4AD5WLbUP7zwrgOqXVNE7DI8PYpKoqt5KBhmBxkp5D0 R4Td1vInP4Dn9CCVnJTgx8g1v8Eb6Ca8HeUE0Ec3zWWrVaTBl6wQxJSWhCxwbzfBs+qH z+Q6ktGGdrE1K0a+S3EUkz+trPejwdn+nKq0/6xD8bgmlH16MJEbO1Od3GXg8lUswL1u i5LGf6El5ySVNnJPTV26TeQRrE0p/sVhT1xrOrLYKkrmzFI62hwLuPmZ33PJD/O/dgjm qdT+lAJW++O4wj9wK8zhn0/mPzHrEzUJK7Uw64jVU5N6agZGc+nnfftQTEZvLg3uqFrR icUA== X-Gm-Message-State: AOAM531Re0eXi7Uuh0w036QriHk+SSmtPlI0ipytKLp59WQBcF6jGU5l P7Nvp94VgNvDvv4/6wAWHTrTk+J6sISozRzK05BtsJ5Ic5cTQN/duP4Gy/DDXfceHSId0oHV9ed mEixnBWFhQ0jPmRE= X-Received: by 2002:a05:6870:a107:b0:ed:9a88:88b8 with SMTP id m7-20020a056870a10700b000ed9a8888b8mr2644054oae.298.1651888725426; Fri, 06 May 2022 18:58:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw74r8xmEPod3P4somLw/hbNd1aqJfKhMfGgmvHhWAXiKbRXYz5zj9iBk9KTqXPt/4sYxebtQ== X-Received: by 2002:a05:6870:a107:b0:ed:9a88:88b8 with SMTP id m7-20020a056870a10700b000ed9a8888b8mr2644042oae.298.1651888725236; Fri, 06 May 2022 18:58:45 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 5/7] multifd: multifd_send_sync_main now returns negative on error Date: Fri, 6 May 2022 22:57:57 -0300 Message-Id: <20220507015759.840466-6-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.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=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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651888821446100001 Even though multifd_send_sync_main() currently emits error_reports, it's callers don't really check it before continuing. Change multifd_send_sync_main() to return -1 on error and 0 on success. Also change all it's callers to make use of this change and possibly fail earlier. (This change is important to next patch on multifd zero copy implementation, to make it sure an error in zero-copy flush does not go unnoticed. Signed-off-by: Leonardo Bras Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Xu --- migration/multifd.h | 2 +- migration/multifd.c | 10 ++++++---- migration/ram.c | 29 ++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/migration/multifd.h b/migration/multifd.h index 7d0effcb03..bcf5992945 100644 --- a/migration/multifd.h +++ b/migration/multifd.h @@ -20,7 +20,7 @@ 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_sync_main(void); -void multifd_send_sync_main(QEMUFile *f); +int multifd_send_sync_main(QEMUFile *f); int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset); =20 /* Multifd Compression flags */ diff --git a/migration/multifd.c b/migration/multifd.c index 2a8c8570c3..15fb668e64 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -566,17 +566,17 @@ void multifd_save_cleanup(void) multifd_send_state =3D NULL; } =20 -void multifd_send_sync_main(QEMUFile *f) +int multifd_send_sync_main(QEMUFile *f) { int i; =20 if (!migrate_use_multifd()) { - return; + return 0; } if (multifd_send_state->pages->num) { if (multifd_send_pages(f) < 0) { error_report("%s: multifd_send_pages fail", __func__); - return; + return -1; } } for (i =3D 0; i < migrate_multifd_channels(); i++) { @@ -589,7 +589,7 @@ void multifd_send_sync_main(QEMUFile *f) if (p->quit) { error_report("%s: channel %d has already quit", __func__, i); qemu_mutex_unlock(&p->mutex); - return; + return -1; } =20 p->packet_num =3D multifd_send_state->packet_num++; @@ -608,6 +608,8 @@ void multifd_send_sync_main(QEMUFile *f) qemu_sem_wait(&p->sem_sync); } trace_multifd_send_sync_main(multifd_send_state->packet_num); + + return 0; } =20 static void *multifd_send_thread(void *opaque) diff --git a/migration/ram.c b/migration/ram.c index a2489a2699..5f5e37f64d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2909,6 +2909,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque) { RAMState **rsp =3D opaque; RAMBlock *block; + int ret; =20 if (compress_threads_save_setup()) { return -1; @@ -2943,7 +2944,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque) ram_control_before_iterate(f, RAM_CONTROL_SETUP); ram_control_after_iterate(f, RAM_CONTROL_SETUP); =20 - multifd_send_sync_main(f); + ret =3D multifd_send_sync_main(f); + if (ret < 0) { + return ret; + } + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); =20 @@ -3052,7 +3057,11 @@ static int ram_save_iterate(QEMUFile *f, void *opaqu= e) out: if (ret >=3D 0 && migration_is_setup_or_active(migrate_get_current()->state)) { - multifd_send_sync_main(rs->f); + ret =3D multifd_send_sync_main(rs->f); + if (ret < 0) { + return ret; + } + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); qemu_fflush(f); ram_transferred_add(8); @@ -3112,13 +3121,19 @@ static int ram_save_complete(QEMUFile *f, void *opa= que) ram_control_after_iterate(f, RAM_CONTROL_FINISH); } =20 - if (ret >=3D 0) { - multifd_send_sync_main(rs->f); - qemu_put_be64(f, RAM_SAVE_FLAG_EOS); - qemu_fflush(f); + if (ret < 0) { + return ret; } =20 - return ret; + ret =3D multifd_send_sync_main(rs->f); + if (ret < 0) { + return ret; + } + + qemu_put_be64(f, RAM_SAVE_FLAG_EOS); + qemu_fflush(f); + + return 0; } =20 static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651889052; cv=none; d=zohomail.com; s=zohoarc; b=UJ3Fh2PQXCEuIBcKx2RVVgdEjxFAwHrJRRJCFY5BrGAj0ClNZseCN2pl0kaV7iFcJ4hNTlryOmAsKHQifh/BqP7ugQs5atmvgXXUjS1by14olvmAMkLdYjLlZmOBmRYBmWUK90Vgb+Cw4+Jlui7XpumpoefaBXyuPAVr2qxUS2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651889052; 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=nKIqzXZ0u4hsOAjTKtMqbZ1MW0BdUgNP96TObuznd/M=; b=XAJaVp+hd8rCPgsdQZzxvpuHWhSq6DfEdqKGZf+OakRAO6nX8DX5ZbTsjOEEzmMfJYlQzp/YinjYvRPsx2efUBBD9Zl4Bj1sTHHZxsO0dAJC2f+VznZ4wM4zYG6j/G32Jdkow1UaDtp8DUqGwTpJdELPTQja36+XCKrzOD9xm/c= 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 1651889052731122.72727857987854; Fri, 6 May 2022 19:04:12 -0700 (PDT) Received: from localhost ([::1]:56366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9nn-0005o5-Ig for importer@patchew.org; Fri, 06 May 2022 22:04:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9if-0005gM-NO for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59258) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9ie-0006jp-4c for qemu-devel@nongnu.org; Fri, 06 May 2022 21:58:53 -0400 Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-206-YgHpQPoGMcmo04wUD_CukA-1; Fri, 06 May 2022 21:58:50 -0400 Received: by mail-ot1-f69.google.com with SMTP id 64-20020a9d0346000000b00605ddf8273aso3592851otv.11 for ; Fri, 06 May 2022 18:58:50 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888731; 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=nKIqzXZ0u4hsOAjTKtMqbZ1MW0BdUgNP96TObuznd/M=; b=a1QBn6YpnL6oQEI+EimjkrcgFXoChYEHdEsQMkxEzwG7KXEdbll8uGk5zG7thE59A7dUtZ VTuXisZzbgYJYiyaQRuC6/nUDWdFR6ufXV9Ys7qGNef+pTw2GWCMSxgX9Bm6aH5QrbGC39 rgw7ZKbgLgyuEUhTcaYjsPUSwvm01Yc= X-MC-Unique: YgHpQPoGMcmo04wUD_CukA-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=nKIqzXZ0u4hsOAjTKtMqbZ1MW0BdUgNP96TObuznd/M=; b=itVTlZuKi3fHN9ZX/mJHtayo5YL5pmXl9T2qQU8am5be2o/donfa6MRE3gEDTJpxsw f2gzaKdQDolC71RpQSJv47q8huzZOFJFvMhf909DcY3BhS0OpmDtBmkYmu5PSY0YqouX QaTtzt5P3AHQIjUtoKtj2EwxM31dh+GMc6sz6iK8MB25tIWFPMCAwyIuPDgSCm92+lyu 4rU8H/wJYz6lrObt4OWVV4ymU8gojOoBtjDhzhU3G9adTzS1Laen8XqPt5t/o5O3gPxY Nln8AmWQ1QbUlp0a7JraYJ7UCz/sU1hw8LD37vl+DDDQsw2n26Rh/KwHH7+8e9/Ad1+Z E96Q== X-Gm-Message-State: AOAM53356QydaNEtQUH7OUqroHR/clg9aqelWM7LvTtWfx51mzeIzXCY mVRl1JtoIrbHI5//lzaXAvys+v+H9quKKuolMgSI0yBfDG7jixL/xEuu/RZacXLrFNvilXgXVYi v4lC+GvF1zsmcdmQ= X-Received: by 2002:a05:6808:3082:b0:326:9043:a8de with SMTP id bl2-20020a056808308200b003269043a8demr2611870oib.239.1651888729449; Fri, 06 May 2022 18:58:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGL543lnXlG54bZrxgkuDbHQCaPlwDSw19nuVu+6969squx3fijvvPnWEVPe9WF8PpjSjYyw== X-Received: by 2002:a05:6808:3082:b0:326:9043:a8de with SMTP id bl2-20020a056808308200b003269043a8demr2611864oib.239.1651888729242; Fri, 06 May 2022 18:58:49 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 6/7] multifd: Send header packet without flags if zero-copy-send is enabled Date: Fri, 6 May 2022 22:57:58 -0300 Message-Id: <20220507015759.840466-7-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651889053905100001 Since d48c3a0445 ("multifd: Use a single writev on the send side"), sending the header packet and the memory pages happens in the same writev, which can potentially make the migration faster. Using channel-socket as example, this works well with the default copying mechanism of sendmsg(), but with zero-copy-send=3Dtrue, it will cause the migration to often break. This happens because the header packet buffer gets reused quite often, and there is a high chance that by the time the MSG_ZEROCOPY mechanism get to send the buffer, it has already changed, sending the wrong data and causing the migration to abort. It means that, as it is, the buffer for the header packet is not suitable for sending with MSG_ZEROCOPY. In order to enable zero copy for multifd, send the header packet on an individual write(), without any flags, and the remanining pages with a writev(), as it was happening before. This only changes how a migration with zero-copy-send=3Dtrue works, not changing any current behavior for migrations with zero-copy-send=3Dfalse. Signed-off-by: Leonardo Bras Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/multifd.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 15fb668e64..2541cd2322 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -617,6 +617,7 @@ static void *multifd_send_thread(void *opaque) MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; int ret =3D 0; + bool use_zero_copy_send =3D migrate_use_zero_copy_send(); =20 trace_multifd_send_thread_start(p->id); rcu_register_thread(); @@ -639,9 +640,14 @@ static void *multifd_send_thread(void *opaque) if (p->pending_job) { uint64_t packet_num =3D p->packet_num; uint32_t flags =3D p->flags; - p->iovs_num =3D 1; p->normal_num =3D 0; =20 + if (use_zero_copy_send) { + p->iovs_num =3D 0; + } else { + p->iovs_num =3D 1; + } + for (int i =3D 0; i < p->pages->num; i++) { p->normal[p->normal_num] =3D p->pages->offset[i]; p->normal_num++; @@ -665,8 +671,18 @@ static void *multifd_send_thread(void *opaque) trace_multifd_send(p->id, packet_num, p->normal_num, flags, p->next_packet_size); =20 - p->iov[0].iov_len =3D p->packet_len; - p->iov[0].iov_base =3D p->packet; + if (use_zero_copy_send) { + /* Send header first, without zerocopy */ + ret =3D qio_channel_write_all(p->c, (void *)p->packet, + p->packet_len, &local_err); + if (ret !=3D 0) { + break; + } + } else { + /* Send header using the same writev call */ + p->iov[0].iov_len =3D p->packet_len; + p->iov[0].iov_base =3D p->packet; + } =20 ret =3D qio_channel_writev_all(p->c, p->iov, p->iovs_num, &local_err); --=20 2.36.0 From nobody Sun May 19 08:26:10 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=1651889179; cv=none; d=zohomail.com; s=zohoarc; b=jvSrKRztrWtE36haqWs4/MkB4JPC++dtNhG5gs/pcnx4yKRjGvqijVlmAgo9HIJiGfr59sKujyihxIFvPoCFdLmf4xNf7Ys5+2eCBjKxszPV383l3r5K2OpHBIK2K8tXDvKp5c6KSB/hg+FeNLmRc3oZFiMd9NU5gMcnO4XfQ/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651889179; 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=j41EFxZl48K8PzXKwjw+VPUyqLUUbXh0uI/r17CYUNI=; b=mMrMdI+/eddfA3J0Kmg5N2Gzbq3ugoNOGhYozfBzdQQs5WAhhn4Cht6xDrhAzQ5QW2Ymr43robupfFOtCMSX5c4NKW6YlJWYQchhCBI+m8BUu4rD7ThznUtiJUKcxq8bFVzOi3cZoEhXPHbdtCO205esBng5li6xZItFDwl+fp8= 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 1651889179671149.48915321264394; Fri, 6 May 2022 19:06:19 -0700 (PDT) Received: from localhost ([::1]:33834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn9pq-0001Dx-46 for importer@patchew.org; Fri, 06 May 2022 22:06:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9iq-0006Hi-SE for qemu-devel@nongnu.org; Fri, 06 May 2022 21:59:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn9ip-0006lx-9D for qemu-devel@nongnu.org; Fri, 06 May 2022 21:59:04 -0400 Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-224-RYVTe6PENpu5Wn9GP1LYTQ-1; Fri, 06 May 2022 21:58:54 -0400 Received: by mail-ot1-f70.google.com with SMTP id c20-20020a056830349400b0060659610972so2050541otu.3 for ; Fri, 06 May 2022 18:58:54 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f0:55e:b3e6:9ebe:4b75:fe72]) by smtp.gmail.com with ESMTPSA id v18-20020a056830141200b0060603221281sm2218124otp.81.2022.05.06.18.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 18:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651888742; 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=j41EFxZl48K8PzXKwjw+VPUyqLUUbXh0uI/r17CYUNI=; b=PEPqO3pLkQ1TdhO7Ogz8kJZXgj24nQQAEf7otQI7xJMvpi4Un7grHov7cTUfMZANOksMOO 8IwzNCJFK0fxd2s8sljQwzIbnMUvC0medGK4s+OeOk1HjUhLFEA9hhGHlzocROe0pqcCPg iYoiheRCjd2Eas+mbYIqkoTkPhdtw9Q= X-MC-Unique: RYVTe6PENpu5Wn9GP1LYTQ-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=j41EFxZl48K8PzXKwjw+VPUyqLUUbXh0uI/r17CYUNI=; b=YfjvsG3w8H1lOIXb9aUDZs/AcuCk5W4e9HUOyStGy3YYKRxJcZIbA+GPGlQcvu2Nq7 C749uC+YUp3kxtDjjfxKQDSxV5ILlPxbZaiNs3PGJtxzon+Hz3yr9OKSZ4BmGlLU9Sln s2cgcIM/A2tgE2Nq4d5OvP9l9uZw2sFWGtzbama/nVv8B2uleOtMKKRJPymG8cBVvLXn K/tz/kiM/k8yX24jRsca0gZoVxTp43ZLKtdLQzjjuAnQNvNd08oRR4m5CNCQ4vzF1mpW yPEo2XwK+5QJUqTJtWfqUeOkaMYMXlMaZaiML4ucinVRHcjpIMYtG0FNT7O5Oe7nrsNv eSSQ== X-Gm-Message-State: AOAM531Tw14Y5wE9vkEMw0LPM8FuEfFbuJn73OkfPjHPGTt0mXes60bD lnYeGtF4ZkhnmSJ0hUarBSwfcnAhzrUC8pxYi5UpSmAp5DazghyFJm2kKhsvHeAG1wEauvZeDV1 gDdocZ3IIoX3yvg8= X-Received: by 2002:a05:6870:5707:b0:de:2cb8:7759 with SMTP id k7-20020a056870570700b000de2cb87759mr5785838oap.20.1651888733444; Fri, 06 May 2022 18:58:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwY0PPqFxy+3E3QSqrMkpF7aaFWfuJFWlKT3Ol7IzEtiTtjzhXdhfJt0m08lK1dLk0T7Fy0MQ== X-Received: by 2002:a05:6870:5707:b0:de:2cb8:7759 with SMTP id k7-20020a056870570700b000de2cb87759mr5785834oap.20.1651888733242; Fri, 06 May 2022 18:58:53 -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 Cc: Leonardo Bras , qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH v12 7/7] multifd: Implement zero copy write in multifd migration (multifd-zero-copy) Date: Fri, 6 May 2022 22:57:59 -0300 Message-Id: <20220507015759.840466-8-leobras@redhat.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220507015759.840466-1-leobras@redhat.com> References: <20220507015759.840466-1-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=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=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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1651889180576100001 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 Reviewed-by: Peter Xu Reviewed-by: Daniel P. Berrang=C3=A9 --- migration/multifd.h | 2 ++ migration/migration.c | 11 ++++++++++- migration/multifd.c | 37 +++++++++++++++++++++++++++++++++++-- migration/socket.c | 5 +++-- 4 files changed, 50 insertions(+), 5 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 2541cd2322..9282ab6aa4 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,20 @@ int multifd_send_sync_main(QEMUFile *f) return -1; } } + + /* + * When using zero-copy, it's necessary to flush the pages before any = of + * the pages can be sent again, so we'll make sure the new version of = the + * pages will always arrive _later_ than the old pages. + * + * Currently we achieve this by flushing the zero-page requested writes + * per ram iteration, but in the future we could potentially optimize = it + * to be less frequent, e.g. only after we finished one whole scanning= of + * all the dirty bitmaps. + */ + + 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 +615,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]; @@ -684,8 +710,8 @@ 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, p->iovs_num, - &local_err); + ret =3D qio_channel_writev_full_all(p->c, p->iov, p->iovs_num,= NULL, + 0, p->write_flags, &local_er= r); if (ret !=3D 0) { break; } @@ -913,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