All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Hanna Reitz" <hreitz@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>,
	qemu-block@nongnu.org, "John Snow" <jsnow@redhat.com>,
	"Thanos Makatos" <thanos.makatos@nutanix.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"John Levon" <john.levon@nutanix.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Cleber Rosa" <crosa@redhat.com>, "Peter Xu" <peterx@redhat.com>,
	"Tejus GK" <tejus.gk@nutanix.com>
Subject: [PULL 01/29] io: invert the return semantics of qio_channel_flush
Date: Thu, 21 May 2026 14:49:15 +0100	[thread overview]
Message-ID: <20260521134943.1714527-2-berrange@redhat.com> (raw)
In-Reply-To: <20260521134943.1714527-1-berrange@redhat.com>

From: Tejus GK <tejus.gk@nutanix.com>

With the kernel's zerocopy notification mechanism, the caller can
determine whether
 * All syscalls successfully used zero copy
 * At least one syscall failed to use zero copy

But, as of now QEMU's IO channel flush function semantics are like
 * 1 => all syscalls failed to use zero copy
 * 0 => at least one syscall successfully used zero copy

This is not aligned with what the kernel reports, and ends up reporting
false negatives for cases like when there's just a single successful
zerocopy amongst a collection of deferred zero-copies during a flush.

Fix this by inverting the return semantics of the IO flush function.

Suggested-by: Peter Xu <peterx@redhat.com>
Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Tejus GK <tejus.gk@nutanix.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 include/io/channel-socket.h |  6 +-----
 include/io/channel.h        |  4 ++--
 io/channel-socket.c         | 16 ++++++++--------
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/include/io/channel-socket.h b/include/io/channel-socket.h
index a1ef3136ea..b07cd61477 100644
--- a/include/io/channel-socket.h
+++ b/include/io/channel-socket.h
@@ -50,11 +50,7 @@ struct QIOChannelSocket {
     ssize_t zero_copy_queued;
     ssize_t zero_copy_sent;
     bool blocking;
-    /**
-     * This flag indicates whether any new data was successfully sent with
-     * zerocopy since the last qio_channel_socket_flush() call.
-     */
-    bool new_zero_copy_sent_success;
+    bool zero_copy_fallback;
 };
 
 
diff --git a/include/io/channel.h b/include/io/channel.h
index 287d10cd6f..98485c9280 100644
--- a/include/io/channel.h
+++ b/include/io/channel.h
@@ -1147,8 +1147,8 @@ int coroutine_mixed_fn qio_channel_writev_full_all(QIOChannel *ioc,
  * 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.
+ *          1 if at least one send failed to use zero copy.
+ *          0 if every send successfully used zero copy.
  */
 
 int qio_channel_flush(QIOChannel *ioc,
diff --git a/io/channel-socket.c b/io/channel-socket.c
index 3053b35ad8..ea2ec84108 100644
--- a/io/channel-socket.c
+++ b/io/channel-socket.c
@@ -72,7 +72,7 @@ qio_channel_socket_new(void)
     sioc->zero_copy_queued = 0;
     sioc->zero_copy_sent = 0;
     sioc->blocking = false;
-    sioc->new_zero_copy_sent_success = false;
+    sioc->zero_copy_fallback = false;
 
     ioc = QIO_CHANNEL(sioc);
     qio_channel_set_feature(ioc, QIO_CHANNEL_FEATURE_SHUTDOWN);
@@ -880,9 +880,9 @@ static int qio_channel_socket_flush_internal(QIOChannel *ioc,
         /* No errors, count successfully finished sendmsg()*/
         sioc->zero_copy_sent += serr->ee_data - serr->ee_info + 1;
 
-        /* If any sendmsg() succeeded using zero copy, mark zerocopy success */
-        if (serr->ee_code != SO_EE_CODE_ZEROCOPY_COPIED) {
-            sioc->new_zero_copy_sent_success = true;
+        if (serr->ee_code == SO_EE_CODE_ZEROCOPY_COPIED) {
+            /* If any sendmsg() fell back to a copy, mark fallback as true */
+            sioc->zero_copy_fallback = true;
         }
     }
 
@@ -900,12 +900,12 @@ static int qio_channel_socket_flush(QIOChannel *ioc,
         return ret;
     }
 
-    if (sioc->new_zero_copy_sent_success) {
-        sioc->new_zero_copy_sent_success = false;
-        return 0;
+    if (sioc->zero_copy_fallback) {
+        sioc->zero_copy_fallback = false;
+        return 1;
     }
 
-    return 1;
+    return 0;
 }
 
 #endif /* QEMU_MSG_ZEROCOPY */
-- 
2.54.0



  reply	other threads:[~2026-05-21 13:51 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 13:49 [PULL v3 00/29] Misc patches for iotests, qom, crypt & io Daniel P. Berrangé
2026-05-21 13:49 ` Daniel P. Berrangé [this message]
2026-05-21 13:49 ` [PULL 02/29] crypto: fix client side anonymous TLS credentials Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 03/29] python: bump qemu.qmp to v0.0.6 Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 04/29] gitlab: ensure all meson jobs capture build/meson-logs by default Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 05/29] iotests: print reason when I/O test is skipped in TAP mode Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 06/29] iotests: remove redundant meson suite for iotests Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 07/29] iotests: ensure all qcow2 I/O tests are able to be run via make Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 08/29] scripts/mtest2make: ensure output has stable sorting Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 09/29] scripts/mtest2make: support optional tests grouping Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 10/29] iotests: add a meson suite / make target per block I/O tests format Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 11/29] docs/devel/testing: expand documentation for 'make check-block' Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 12/29] iotests: add nbd and luks to the I/O test suites Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 13/29] iotests: use 'driver' as collective term for either format or protocol Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 14/29] iotests: validate dmsetup result in test 128 Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 15/29] iotests: fix check for sudo access in LUKS I/O test Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 16/29] iotests: mark 151, 181, 185 & 308 as flaky tests Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 17/29] gitlab: add jobs for thorough block tests Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 18/29] gitlab: remove I/O tests from build-tcg-disabled job Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 19/29] qom: add trace events for object/property lifecycle Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 20/29] hw/vfio-user: use a valid object ID for iothread Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 21/29] qom: validate ID format when creating objects Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 22/29] qom: make errp last param in methods taking va_list Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 23/29] qom: shorten name of object_set_properties_from_keyval Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 24/29] qom: have object_set_props_keyval return bool Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 25/29] qom: move object_set_prop_keyval into object.c Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 26/29] qom: add object_new_with_props_from_qdict Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 27/29] qom: fix ability to create objects without a parent Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 28/29] qom: allow object_new_with_prop* to trigger module loading Daniel P. Berrangé
2026-05-21 13:49 ` [PULL 29/29] qom: drop user_creatable_add_type method Daniel P. Berrangé
2026-05-24 19:13 ` [PULL v3 00/29] Misc patches for iotests, qom, crypt & io Stefan Hajnoczi
  -- strict thread matches above, loose matches on Subject: below --
2026-05-20  9:13 [PULL 00/29] Misc next patches Daniel P. Berrangé
2026-05-20  9:13 ` [PULL 01/29] io: invert the return semantics of qio_channel_flush Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260521134943.1714527-2-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=clg@redhat.com \
    --cc=crosa@redhat.com \
    --cc=hreitz@redhat.com \
    --cc=john.levon@nutanix.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=tejus.gk@nutanix.com \
    --cc=thanos.makatos@nutanix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.