From patchwork Wed Jun 8 21:04:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 12874660 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2C47C43334 for ; Wed, 8 Jun 2022 21:06:40 +0000 (UTC) Received: from localhost ([::1]:59642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nz2sx-0003Bc-MJ for qemu-devel@archiver.kernel.org; Wed, 08 Jun 2022 17:06:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz2qj-0001lX-L3 for qemu-devel@nongnu.org; Wed, 08 Jun 2022 17:04:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:35550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz2qi-00048J-6N for qemu-devel@nongnu.org; Wed, 08 Jun 2022 17:04:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654722259; 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; bh=j3Nz/ACzzNuOiSk8tGSrM9ZLKWcQ64Xrz23dnSYVlps=; b=aU+7lcd6MMLw+AgQEClMP6n9H18/o2OyAMKbA6qIUWDSazjG7fOCKW54eWETEjJatoSYrd Xh3j1QSq/h0+wCdSfr28fyT3Q0gQVed6Lwl/B+I9PfQ6lbN+9TNaskikoymWva61PIwq6z aC9KMcwsLMZzfz/EDbOrGSroHvSUx80= Received: from mail-oa1-f69.google.com (mail-oa1-f69.google.com [209.85.160.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-195-cAPV3E_VO06XEQAVfp0GLw-1; Wed, 08 Jun 2022 17:04:18 -0400 X-MC-Unique: cAPV3E_VO06XEQAVfp0GLw-1 Received: by mail-oa1-f69.google.com with SMTP id 586e51a60fabf-f2bdeb5298so12906242fac.5 for ; Wed, 08 Jun 2022 14:04:18 -0700 (PDT) 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:mime-version :content-transfer-encoding; bh=j3Nz/ACzzNuOiSk8tGSrM9ZLKWcQ64Xrz23dnSYVlps=; b=Lx6A4CGWR4cWp3svQTqsN4XxfoM5uORPpVB2jjN4wc0s76hE7uU3nw2PsQGSS7nFMX zAfpu4EC5Wu9QYK4A8cVOZ80Gbzb7jmtxHRRFenkxjzYl73Ut4H7MB3h0QeZPbC8pwv2 jRykfJt0j3+4ux9DWTN0cs+L3qRw90uHpKdSH0nYrJGe+y2B2i29TfHuXAV1G/69AYz0 xFYaoTlzOaSA6po9QR/j1IGTaOQncTQA3mSaP5NB3QHEwy/BmHQhk1rZOCUPaNaPKG4b 334jT1+gjRkOoIHqkl1mSguoNFhxyuI5eVRfGMCu2vmrFEC4aEat7EF+mIT+e/X42sJw e2NA== X-Gm-Message-State: AOAM531665HYaR8hXZurzuzrgO7ICgf0ut49e9PJrLEB22w8wB22E8w1 Aq6ePNC/gUYt3LZzmI6P8m+MDOpycU0ai4jnFdmiaGMjtm/R86w22c97ucX0YABDAG2f9cnGond BHtVikKO3Nq3xJTE= X-Received: by 2002:a05:6808:159a:b0:32b:80e3:f746 with SMTP id t26-20020a056808159a00b0032b80e3f746mr3605477oiw.144.1654722257208; Wed, 08 Jun 2022 14:04:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrAa/ICAXvJ0vleNQxcdmKaA3kqbKS9J1VM/FPsc4wakmb7wLyPkpK0Nz6HbKp/skNnDUROA== X-Received: by 2002:a05:6808:159a:b0:32b:80e3:f746 with SMTP id t26-20020a056808159a00b0032b80e3f746mr3605469oiw.144.1654722257029; Wed, 08 Jun 2022 14:04:17 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f1:d1b1:8b15:218b:6b0e:5260]) by smtp.gmail.com with ESMTPSA id l14-20020a0568302b0e00b0060b66e2eaaesm11382384otv.38.2022.06.08.14.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 14:04:16 -0700 (PDT) From: Leonardo Bras To: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Peter Xu , =?utf-8?b?5b6Q6Zev?= , David Gilbert , Juan Quintela Cc: Leonardo Bras , qemu-devel@nongnu.org Subject: [PATCH v2 1/2] QIOChannelSocket: Reduce ifdefs to improve readability Date: Wed, 8 Jun 2022 18:04:02 -0300 Message-Id: <20220608210403.84006-1-leobras@redhat.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" During implementation of MSG_ZEROCOPY feature, a lot of #ifdefs were introduced, particularly at qio_channel_socket_writev(). Rewrite some of those changes so it's easier to read. ... Signed-off-by: Leonardo Bras --- io/channel-socket.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/io/channel-socket.c b/io/channel-socket.c index dc9c165de1..ef7c7cfbac 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -554,6 +554,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc, size_t fdsize = sizeof(int) * nfds; struct cmsghdr *cmsg; int sflags = 0; + bool zero_copy_enabled = false; memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); @@ -581,6 +582,7 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc, #ifdef QEMU_MSG_ZEROCOPY if (flags & QIO_CHANNEL_WRITE_FLAG_ZERO_COPY) { sflags = MSG_ZEROCOPY; + zero_copy_enabled = true; } #endif @@ -592,15 +594,13 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc, return QIO_CHANNEL_ERR_BLOCK; case EINTR: goto retry; -#ifdef QEMU_MSG_ZEROCOPY case ENOBUFS: - if (sflags & MSG_ZEROCOPY) { + if (zero_copy_enabled) { error_setg_errno(errp, errno, "Process can't lock enough memory for using MSG_ZEROCOPY"); return -1; } break; -#endif } error_setg_errno(errp, errno, From patchwork Wed Jun 8 21:04:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leonardo Bras X-Patchwork-Id: 12874661 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2D0D3C43334 for ; Wed, 8 Jun 2022 21:06:44 +0000 (UTC) Received: from localhost ([::1]:59756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nz2t0-0003GZ-70 for qemu-devel@archiver.kernel.org; Wed, 08 Jun 2022 17:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55384) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz2ql-0001mi-Ks for qemu-devel@nongnu.org; Wed, 08 Jun 2022 17:04:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24141) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nz2qk-00048T-6U for qemu-devel@nongnu.org; Wed, 08 Jun 2022 17:04:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654722261; 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=NWOcKXALzYETQDPwBBeoZE/GQdWJfvnn2yDZFDnjDr0=; b=C1K9CNo1uF8wms8x50D79or7A0I/X7U/1Sn9gqSYsHKgwbooOOTbMfk0uL6FAn3QwnZ3IU epJjAOKjc1oHDX6iHSzyCQY2uPnLeXvQMGrwg8/sXKXyAjQhQGV8PQknLGNjYGujHcKUd/ KHjFKgSLm9o7AenzFRidcGNQ8/vR6t0= 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-624-pjK6Rc-oOBux6agkkVqVuw-1; Wed, 08 Jun 2022 17:04:20 -0400 X-MC-Unique: pjK6Rc-oOBux6agkkVqVuw-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-f344ea88d9so12921876fac.11 for ; Wed, 08 Jun 2022 14:04:20 -0700 (PDT) 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=NWOcKXALzYETQDPwBBeoZE/GQdWJfvnn2yDZFDnjDr0=; b=TOLy72myHyurD5hymcm9EhdLz6bUrwhglvAQQr31C5lWC6XcR1w8Ykmu5nHSA7AFqE l6svXpRQ7ighP1YUPSiwyhIYFMecqHuuOW240R0AuHBX+kRIkNm2Ek6A2fAncoGTwJia NLz7Af4e+hPMHYNU9VlaoQBlYRoCW9DtZeWRxEW6xXG38yLB5gBtcOWeFInavY4N1GY6 8hpp02PCVKrL6T/DRIACAlnLJ6o4YRjqAlmycJlIIqI+0F0RwbiNqWG2qpGZqdNqQjj4 HTkJedyBi08m4LpXdboeKqzO+IRJpckYY9iTW+6Gy4qXUKB2aFbQ4zUg9MxU7IqqrEqz JLrQ== X-Gm-Message-State: AOAM532QtGi+OmxBTzyg9oaRtJxBXrC8LaOoMArv+RkmgHCgk6/d9ejG xzGpt2yiXe3knc7l4weB+mHGLMyYv822wFdE7GCXkGRFdVa4Oie/uvWvAKzuusz+9YfvDRwa9UT z2xHfEFy/LKud2XI= X-Received: by 2002:a05:6808:e8d:b0:32e:1e76:a60b with SMTP id k13-20020a0568080e8d00b0032e1e76a60bmr3624958oil.21.1654722259742; Wed, 08 Jun 2022 14:04:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQ3+H+5wvUXc1bHnGjmfkAGin6JwcmpzMr4nX2M7aCR53gI3lB3tgN0ty5zpF9a34WbjPb4A== X-Received: by 2002:a05:6808:e8d:b0:32e:1e76:a60b with SMTP id k13-20020a0568080e8d00b0032e1e76a60bmr3624946oil.21.1654722259592; Wed, 08 Jun 2022 14:04:19 -0700 (PDT) Received: from localhost.localdomain ([2804:431:c7f1:d1b1:8b15:218b:6b0e:5260]) by smtp.gmail.com with ESMTPSA id l14-20020a0568302b0e00b0060b66e2eaaesm11382384otv.38.2022.06.08.14.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 14:04:19 -0700 (PDT) From: Leonardo Bras To: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Peter Xu , =?utf-8?b?5b6Q6Zev?= , David Gilbert , Juan Quintela Cc: Leonardo Bras , qemu-devel@nongnu.org Subject: [PATCH v2 2/2] QIOChannelSocket: Fix zero-copy send so socket flush works Date: Wed, 8 Jun 2022 18:04:03 -0300 Message-Id: <20220608210403.84006-2-leobras@redhat.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220608210403.84006-1-leobras@redhat.com> References: <20220608210403.84006-1-leobras@redhat.com> MIME-Version: 1.0 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Somewhere between v6 and v7 the of the zero-copy-send patchset a crucial part of the flushing mechanism got missing: incrementing zero_copy_queued. Without that, the flushing interface becomes a no-op, and there is no guarantee the buffer is really sent. This can go as bad as causing a corruption in RAM during migration. Fixes: 2bc58ffc2926 ("QIOChannelSocket: Implement io_writev zero copy flag & io_flush for CONFIG_LINUX") Reported-by: 徐闯 Signed-off-by: Leonardo Bras --- io/channel-socket.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/io/channel-socket.c b/io/channel-socket.c index ef7c7cfbac..ca4cae930f 100644 --- a/io/channel-socket.c +++ b/io/channel-socket.c @@ -607,6 +607,11 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc, "Unable to write to socket"); return -1; } + + if (zero_copy_enabled) { + sioc->zero_copy_queued++; + } + return ret; } #else /* WIN32 */