From nobody Mon Aug 24 18:55:00 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1779371498; cv=none; d=zohomail.com; s=zohoarc; b=DldxH3hnksyWXUvTx+/lwR57/kkBy3gJuLG+bqojKhLs73xVZt5JVhJWF0c81auVBREcrIUtWkntj5fK7fJaX9dv5YODKyUy3aGPYwxXTGKYT9LrWaw574A9+zv7kSHMFW+8Fr6EZR/5PNhRioGfomRYaaNorqWoB+6sCtVPvy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1779371498; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=j6ycJyS58u8wV36TEg6I3IuF42L1x613e3hNw/t4uT4=; b=dgkuq394+Z49340oeyv9pzpF5HnYm2Mb3Gv2QRtMVueAfyZk9bcj2VaCN3sZNdJ1w8HHAu3dTrdvmKShm5LaWQ1CKoS74QZD07m6dA3++KJi6nAQ4WwrKxd2SVeZZstTxGwNLuSsVp4dd2rdpDbT0Eey/TYpEMXhVE76MRe2G1E= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779371498692626.4047305129434; Thu, 21 May 2026 06:51:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQ3n4-0000aO-Om; Thu, 21 May 2026 09:50:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ3mz-0000ZK-77 for qemu-devel@nongnu.org; Thu, 21 May 2026 09:50:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQ3mw-0004lH-Ew for qemu-devel@nongnu.org; Thu, 21 May 2026 09:50:16 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-449-NejNHv8MPN2RFjT9DTb9Ww-1; Thu, 21 May 2026 09:50:06 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4A37A1801359; Thu, 21 May 2026 13:49:55 +0000 (UTC) Received: from berrange.com (unknown [10.44.33.98]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 97D951956053; Thu, 21 May 2026 13:49:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779371411; 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=j6ycJyS58u8wV36TEg6I3IuF42L1x613e3hNw/t4uT4=; b=HBcsD+/Gba74AQc66HUX2IO+z+dG5jbynsigB/dfpiEWukKK9hXiYJ9subgcO0gvIKcrFf b2+r6vmYC8iFWhBpuUoNNLsCNFsB7osJIxQqtGsebac56lZvWsR3FhZy+Tc+bBD8nsEiGe rWo86c00rnioRlU6LPPOAEILaFEYAz0= X-MC-Unique: NejNHv8MPN2RFjT9DTb9Ww-1 X-Mimecast-MFC-AGG-ID: NejNHv8MPN2RFjT9DTb9Ww_1779371405 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Hanna Reitz , Pierrick Bouvier , Paolo Bonzini , Kevin Wolf , qemu-block@nongnu.org, John Snow , Thanos Makatos , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= , John Levon , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Cleber Rosa , Peter Xu , Tejus GK Subject: [PULL 01/29] io: invert the return semantics of qio_channel_flush Date: Thu, 21 May 2026 14:49:15 +0100 Message-ID: <20260521134943.1714527-2-berrange@redhat.com> In-Reply-To: <20260521134943.1714527-1-berrange@redhat.com> References: <20260521134943.1714527-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 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=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.445, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1779371511652158500 From: Tejus GK 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 =3D> all syscalls failed to use zero copy * 0 =3D> 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 Suggested-by: Daniel P. Berrang=C3=A9 Signed-off-by: Tejus GK Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 --- 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; }; =20 =20 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(QI= OChannel *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. */ =20 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 =3D 0; sioc->zero_copy_sent =3D 0; sioc->blocking =3D false; - sioc->new_zero_copy_sent_success =3D false; + sioc->zero_copy_fallback =3D false; =20 ioc =3D 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 +=3D serr->ee_data - serr->ee_info + 1; =20 - /* If any sendmsg() succeeded using zero copy, mark zerocopy succe= ss */ - if (serr->ee_code !=3D SO_EE_CODE_ZEROCOPY_COPIED) { - sioc->new_zero_copy_sent_success =3D true; + if (serr->ee_code =3D=3D SO_EE_CODE_ZEROCOPY_COPIED) { + /* If any sendmsg() fell back to a copy, mark fallback as true= */ + sioc->zero_copy_fallback =3D true; } } =20 @@ -900,12 +900,12 @@ static int qio_channel_socket_flush(QIOChannel *ioc, return ret; } =20 - if (sioc->new_zero_copy_sent_success) { - sioc->new_zero_copy_sent_success =3D false; - return 0; + if (sioc->zero_copy_fallback) { + sioc->zero_copy_fallback =3D false; + return 1; } =20 - return 1; + return 0; } =20 #endif /* QEMU_MSG_ZEROCOPY */ --=20 2.54.0