From nobody Fri Nov 14 16:55:18 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=1762279018; cv=none; d=zohomail.com; s=zohoarc; b=VSXP+Oi9yNXQnU1KPctcj+M3H14o6pkvqQ8DTmHCwJag63cX362wkru0hZvAVc7GNw6pIptuT34WXXvosDjEM8J/Ss1J4LcknuLYvUkP5MkP06cW9/r+WI2K22gRURnkD8eMD6GyWl8DA2QpGvEtk9WCrfxCumV1lqHxHf4zJac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762279018; 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=RhVA0YubTi5SGRuSN0fM7JVsTglFF5gQoqp/tSqn62I=; b=M+185mnjwVBX8mt69DReDcfPaDknGNtNccEvGRAes0OLywVkIYQLschJk0qJm1mjXXPZDv+ldGcIGp7ZonSDnmjPp21upJnmCdNTVH2P3OjMwvMSwbqhmKjZMLSYzTNM6wrCVcffpR8Jcj//1BvJoGzItpWbb7rHEfkPQpWrtYk= 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 1762279018284690.3252986912989; Tue, 4 Nov 2025 09:56:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vGLGI-0002Ai-18; Tue, 04 Nov 2025 12:56:15 -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 1vGLEo-0000q2-Qu for qemu-devel@nongnu.org; Tue, 04 Nov 2025 12:54:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vGLEn-0006iZ-58 for qemu-devel@nongnu.org; Tue, 04 Nov 2025 12:54:34 -0500 Received: from mx-prod-mc-06.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-134-A7m4YXY_MaO2vCl-nPpWtA-1; Tue, 04 Nov 2025 12:54:31 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34028180060D; Tue, 4 Nov 2025 17:54:30 +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 E4711180044F; Tue, 4 Nov 2025 17:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762278872; 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=RhVA0YubTi5SGRuSN0fM7JVsTglFF5gQoqp/tSqn62I=; b=MVi6KrYPPkQN1WGXe1nBkXzjwa23ThQBml1PPtiKNsIWAFRVs7dcvIXtZTRW+MsHdH+6DK llBhUeQYPCg0CE1QN/zJq01VYTJv0Wn1ktsPe+zHADiJhhRSOo22b3fhEmEc06cN6KbW5W 8Z0MpgRuGaZdy+WVVut/9h8tcMd96qw= X-MC-Unique: A7m4YXY_MaO2vCl-nPpWtA-1 X-Mimecast-MFC-AGG-ID: A7m4YXY_MaO2vCl-nPpWtA_1762278870 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [PULL 03/27] aio-posix: fix spurious return from ->wait() due to signals Date: Tue, 4 Nov 2025 18:53:51 +0100 Message-ID: <20251104175415.525388-4-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.133.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: 1762279021047154100 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi io_uring_enter(2) only returns -EINTR in some cases when interrupted by a signal. Therefore the while loop in fdmon_io_uring_wait() is incomplete and can lead to a spurious early return. Handle the case when a signal interrupts io_uring_enter(2) but the syscall returns the number of SQEs submitted (that takes priority over -EINTR). This patch probably makes little difference for QEMU, but the test suite relies on the exact pattern of aio_poll() return values, so it's best to hide this io_uring syscall interface quirk. Here is the strace of test-aio receiving 3 SIGCONT signals after this fix has been applied. Notice how the io_uring_enter(2) return value is 1 the first time because an SQE was submitted, but -EINTR the other times: eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK) =3D 9 io_uring_enter(7, 1, 0, 0, NULL, 8) =3D 1 clock_nanosleep(CLOCK_REALTIME, 0, {tv_sec=3D1, tv_nsec=3D0}, 0x7ffe38a46= 240) =3D 0 io_uring_enter(7, 1, 1, IORING_ENTER_GETEVENTS, NULL, 8) =3D 1 --- SIGCONT {si_signo=3DSIGCONT, si_code=3DSI_USER, si_pid=3D596096, si_u= id=3D1000} --- io_uring_enter(7, 0, 1, IORING_ENTER_GETEVENTS, NULL, 8) =3D -1 EINTR (In= terrupted system call) --- SIGCONT {si_signo=3DSIGCONT, si_code=3DSI_USER, si_pid=3D596096, si_u= id=3D1000} --- io_uring_enter(7, 0, 1, IORING_ENTER_GETEVENTS, NULL, 8 <... io_uring_enter resumed>) =3D -1 EINTR (Interrupted system call) --- SIGCONT {si_signo=3DSIGCONT, si_code=3DSI_USER, si_pid=3D596096, si_u= id=3D1000} --- io_uring_enter(7, 0, 1, IORING_ENTER_GETEVENTS, NULL, 8 <... io_uring_enter resumed>) =3D 0 Reported-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-ID: <20251104022933.618123-4-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- util/fdmon-io_uring.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/util/fdmon-io_uring.c b/util/fdmon-io_uring.c index b64ce42513..3d8638b0e5 100644 --- a/util/fdmon-io_uring.c +++ b/util/fdmon-io_uring.c @@ -299,9 +299,16 @@ static int fdmon_io_uring_wait(AioContext *ctx, AioHan= dlerList *ready_list, =20 fill_sq_ring(ctx); =20 + /* + * Loop to handle signals in both cases: + * 1. If no SQEs were submitted, then -EINTR is returned. + * 2. If SQEs were submitted then the number of SQEs submitted is retu= rned + * rather than -EINTR. + */ do { ret =3D io_uring_submit_and_wait(&ctx->fdmon_io_uring, wait_nr); - } while (ret =3D=3D -EINTR); + } while (ret =3D=3D -EINTR || + (ret >=3D 0 && wait_nr > io_uring_cq_ready(&ctx->fdmon_io_uri= ng))); =20 assert(ret >=3D 0); =20 --=20 2.51.1