From nobody Fri Nov 14 18:19:21 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=1762223543; cv=none; d=zohomail.com; s=zohoarc; b=IHToQy7zjbugwTpzrdJEElGEshfQBJg2uV4Mcc5UUOgbvcIOucmSbEPTxYsFUiqS+IH4nKefABz9MBTpjIvA7gcwg6fJxPtDcnxTgc2aH5LKag6cK7qqIG+aY400z/ULpO1gsGz98ZEAp/oljxPits3cTe82ZFyaApDiDRPXxak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1762223543; 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=0oFHTWnYvTpTuorWMlOYX+CfxVfYYLPx7SRGFBc8MRQ=; b=m5Ff/AZRasFmolyWF5vS5riYSrkVU+0EZoplp0Wyu312Wg65HoKbW4v9Z4CnvtvCcv/N9dXQ8lqotImDrVJKy0wLgLNbwcQbhpAJBIUyOeRZ8YHDqOeHUCzYI552TXUqdmqCgYsWXMwUAyUZbN+eYKqeipxGjVCXDroMb2s99x8= 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 1762223543520812.1373522612879; Mon, 3 Nov 2025 18:32:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vG6nz-0006yr-4o; Mon, 03 Nov 2025 21:29:55 -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 1vG6nx-0006yc-E3 for qemu-devel@nongnu.org; Mon, 03 Nov 2025 21:29:53 -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 1vG6nv-0003uf-Ni for qemu-devel@nongnu.org; Mon, 03 Nov 2025 21:29:53 -0500 Received: from mx-prod-mc-03.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-244-1ayQDKlDP5m2roXM0NQamg-1; Mon, 03 Nov 2025 21:29:47 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C05711956053; Tue, 4 Nov 2025 02:29:45 +0000 (UTC) Received: from localhost (unknown [10.2.16.6]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CBE5719560A2; Tue, 4 Nov 2025 02:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762223391; 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=0oFHTWnYvTpTuorWMlOYX+CfxVfYYLPx7SRGFBc8MRQ=; b=FtWIu86acJ2kiviKWZ1/b6kBwta+oxDT6z9F6b75FiTndM2PrWW7w4XO2QbHt3vIwJVMUK ngnzwLwk6eJF2CXoO+rQAErqb6opiTk+FeefxDRWUbJ39rYkEabB1RLVPegZXN8a+APo8Z WDwmFMeTtENTa8n33hkPz54Zo9e9PI8= X-MC-Unique: 1ayQDKlDP5m2roXM0NQamg-1 X-Mimecast-MFC-AGG-ID: 1ayQDKlDP5m2roXM0NQamg_1762223386 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Kevin Wolf , eblake@redhat.com, Hanna Czenczek , qemu-block@nongnu.org, Paolo Bonzini , Fam Zheng , hibriansong@gmail.com Subject: [PATCH v6 03/15] aio-posix: fix spurious return from ->wait() due to signals Date: Mon, 3 Nov 2025 21:29:21 -0500 Message-ID: <20251104022933.618123-4-stefanha@redhat.com> In-Reply-To: <20251104022933.618123-1-stefanha@redhat.com> References: <20251104022933.618123-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1762223551352158500 Content-Type: text/plain; charset="utf-8" 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 --- 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