From nobody Fri Nov 14 16:55:17 2025 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=1762279201; cv=none; d=zohomail.com; s=zohoarc; b=L6MuHpdrQq9/0F/SPCNhbPjo3xWvTYiACjJUw8vWF+fY/XQrCOFTnpT09dA3ypF2LxPvHKoxJ6mgTZEaJbIsx2V+uKtTA8M0ZqdbbuuA58OHw57WzrCDpwvexR1sSbTYLAUz0f7dpzFwM+B8flfxBks5PGEDQiSvvOdc4n95tBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762279201; h=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=qpHxihogj8h+yMIXX+DuGnTIF0C4jAPL+8wqSX+UNzw=; b=JFp9KaTFwzVYsS9kIyEI6w0qAzLifS/tJ5lRgKwHVTI/hm9BsiJoe1wa2v94+MNOZx2dUza03VSrrt1TT097M2/fwiy9biJSZJlvN8b3OFR/zwbvyqxPqKZArK5WxraDSNr0e3aJdI/9mNszToF5pQ2+3L9XGpVBqD+ovtUQpDA= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1762279201197749.6300666475137; Tue, 4 Nov 2025 10:00:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGLJ3-00048U-QB; Tue, 04 Nov 2025 12:58:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGLF2-00010R-2B for qemu-devel@nongnu.org; Tue, 04 Nov 2025 12:54:50 -0500 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 1vGLF0-0006mM-H3 for qemu-devel@nongnu.org; Tue, 04 Nov 2025 12:54:47 -0500 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-225-3s3mAvs_NLi8bH4x5DttEw-1; Tue, 04 Nov 2025 12:54:43 -0500 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8F74A195608D; Tue, 4 Nov 2025 17:54:42 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.45.226.47]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C4121800451; Tue, 4 Nov 2025 17:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762278885; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qpHxihogj8h+yMIXX+DuGnTIF0C4jAPL+8wqSX+UNzw=; b=JoNIQK5uOYnGKmNAKX4sQ4lXIRVm1+hZUcKVsT/uXe/lV9923DrohbWxA7ZLp+iSD1/053 rmKp+8fR68NchOUhs47pyQS9KKtE+FA8t3I0sI36dtqkQhJIYuQFyC+NfJSnCL00/x9WbB E6sFm7nSUeTFRYiIruM9mlZPYBz+eR0= X-MC-Unique: 3s3mAvs_NLi8bH4x5DttEw-1 X-Mimecast-MFC-AGG-ID: 3s3mAvs_NLi8bH4x5DttEw_1762278882 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 10/27] aio-posix: gracefully handle io_uring_queue_init() failure Date: Tue, 4 Nov 2025 18:53:58 +0100 Message-ID: <20251104175415.525388-11-kwolf@redhat.com> In-Reply-To: <20251104175415.525388-1-kwolf@redhat.com> References: <20251104175415.525388-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 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=kwolf@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.788, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=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: 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: 1762279202496154100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi io_uring may not be available at runtime due to system policies (e.g. the io_uring_disabled sysctl) or creation could fail due to file descriptor resource limits. Handle failure scenarios as follows: If another AioContext already has io_uring, then fail AioContext creation so that the aio_add_sqe() API is available uniformly from all QEMU threads. Otherwise fall back to epoll(7) if io_uring is unavailable. Notes: - Update the comment about selecting the fastest fdmon implementation. At this point it's not about speed anymore, it's about aio_add_sqe() API availability. - Uppercase the error message when converting from error_report() to error_setg_errno() for consistency (but there are instances of lowercase in the codebase). - It's easier to move the #ifdefs from aio-posix.h to aio-posix.c. Signed-off-by: Stefan Hajnoczi Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Message-ID: <20251104022933.618123-11-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- util/aio-posix.h | 12 ++---------- util/aio-posix.c | 28 +++++++++++++++++++++++++--- util/fdmon-io_uring.c | 5 +++-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/util/aio-posix.h b/util/aio-posix.h index f9994ed79e..dfa1a51c0b 100644 --- a/util/aio-posix.h +++ b/util/aio-posix.h @@ -18,6 +18,7 @@ #define AIO_POSIX_H =20 #include "block/aio.h" +#include "qapi/error.h" =20 struct AioHandler { GPollFD pfd; @@ -72,17 +73,8 @@ static inline void fdmon_epoll_disable(AioContext *ctx) #endif /* !CONFIG_EPOLL_CREATE1 */ =20 #ifdef CONFIG_LINUX_IO_URING -bool fdmon_io_uring_setup(AioContext *ctx); +bool fdmon_io_uring_setup(AioContext *ctx, Error **errp); void fdmon_io_uring_destroy(AioContext *ctx); -#else -static inline bool fdmon_io_uring_setup(AioContext *ctx) -{ - return false; -} - -static inline void fdmon_io_uring_destroy(AioContext *ctx) -{ -} #endif /* !CONFIG_LINUX_IO_URING */ =20 #endif /* AIO_POSIX_H */ diff --git a/util/aio-posix.c b/util/aio-posix.c index 9806a75c12..c0285a26a3 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -16,6 +16,7 @@ #include "qemu/osdep.h" #include "block/block.h" #include "block/thread-pool.h" +#include "qapi/error.h" #include "qemu/main-loop.h" #include "qemu/lockcnt.h" #include "qemu/rcu.h" @@ -724,10 +725,29 @@ bool aio_context_setup(AioContext *ctx, Error **errp) ctx->epollfd =3D -1; ctx->epollfd_tag =3D NULL; =20 - /* Use the fastest fd monitoring implementation if available */ - if (fdmon_io_uring_setup(ctx)) { - return true; +#ifdef CONFIG_LINUX_IO_URING + { + static bool need_io_uring; + Error *local_err =3D NULL; /* ERRP_GUARD() doesn't handle error_ab= ort */ + + /* io_uring takes precedence because it provides aio_add_sqe() sup= port */ + if (fdmon_io_uring_setup(ctx, &local_err)) { + /* + * If one AioContext gets io_uring, then all AioContexts need = io_uring + * so that aio_add_sqe() support is available across all threa= ds. + */ + need_io_uring =3D true; + return true; + } + if (need_io_uring) { + error_propagate(errp, local_err); + return false; + } + + /* Silently fall back on systems where io_uring is unavailable */ + error_free(local_err); } +#endif /* CONFIG_LINUX_IO_URING */ =20 fdmon_epoll_setup(ctx); return true; @@ -735,7 +755,9 @@ bool aio_context_setup(AioContext *ctx, Error **errp) =20 void aio_context_destroy(AioContext *ctx) { +#ifdef CONFIG_LINUX_IO_URING fdmon_io_uring_destroy(ctx); +#endif =20 qemu_lockcnt_lock(&ctx->list_lock); fdmon_epoll_disable(ctx); diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index 0a5ec5ead6..9f25d6d6db 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -45,6 +45,7 @@ =20 #include "qemu/osdep.h" #include +#include "qapi/error.h" #include "qemu/rcu_queue.h" #include "aio-posix.h" =20 @@ -373,7 +374,7 @@ static const FDMonOps fdmon_io_uring_ops =3D { .gsource_dispatch =3D fdmon_io_uring_gsource_dispatch, }; =20 -bool fdmon_io_uring_setup(AioContext *ctx) +bool fdmon_io_uring_setup(AioContext *ctx, Error **errp) { int ret; =20 @@ -381,6 +382,7 @@ bool fdmon_io_uring_setup(AioContext *ctx) =20 ret =3D io_uring_queue_init(FDMON_IO_URING_ENTRIES, &ctx->fdmon_io_uri= ng, 0); if (ret !=3D 0) { + error_setg_errno(errp, -ret, "Failed to initialize io_uring"); return false; } =20 @@ -388,7 +390,6 @@ bool fdmon_io_uring_setup(AioContext *ctx) ctx->fdmon_ops =3D &fdmon_io_uring_ops; ctx->io_uring_fd_tag =3D g_source_add_unix_fd(&ctx->source, ctx->fdmon_io_uring.ring_fd, G_IO_IN); - return true; } =20 --=20 2.51.1