Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4959581pxj; Tue, 22 Jun 2021 11:46:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8EgS5ZF460IhXzeCF3z3mIG0/qrDp9j8+N8BVv+vTzburo+D4ILzs09HzwtZXDVtujgL9 X-Received: by 2002:a92:7f07:: with SMTP id a7mr72441ild.202.1624387589249; Tue, 22 Jun 2021 11:46:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624387589; cv=none; d=google.com; s=arc-20160816; b=sAHKhrD6eI98lIRgZ6UEzGPv1NirFp8EeGP1dGsVJmjUKKXZrmqwBsQN/Qt/F8sPtz wFoATcvu6KrH76W04Jd3tDXcBYwV95VoMZXCzvWr5lWywnot1vaZxT3J/jpmzs8O8FQG 9Zt5FaX6kz0cdLOt5HAV0HhwnDjTUWu8kPJw3KQDJ9/Iracqs6mCTSqC0BBr1Yjb0dRV MGzd0gYGzGrzscgCKHqfDidBzlKBqRy4nX9g6kZVkf/5xgnZOhHeZyx/2MUeYrbvs+5L KZ4VtEUkdYMO/R57czSSn+xm6ROn5DrNwk0eW9a/Ex24NmgJR/kNcuBXHLOK5HRLwnF6 os8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:references:in-reply-to:message-id:cc:to :from:date; bh=vZ9oy/lewu/c+gvc7KYM6Z59qeRcskvjO90hmAWe2ek=; b=WnhQiAz74fE2Ij3ifkt3qc82rBa2Hgr4wyo7pujvujbcEHcCt4cU9/+XfO4+hA5zAh wk+D0UvP7ytLbGbfmuQ5vBcM5c742qPiX6IW4PJKgeaKwc0c9lHD2LpYmquHW8L/jbyv FUgpMlIo4A/OiPwjRJPhMHPNIU0g53qebYUf6mxe+7qHQw77qBsfRCR2Gt5ojgRQr3Su 7/LmKAPLervOJqncchLUezVbMzZoyNQJXkEdPFBHFrIxBDE/OslGTzYYwY9avXFbn6rI mV6NR0YRK7J8MNhmUNXbF3GiqQy9/QWeptVhNs9GBioH4DEJl8kpnyCxHCEIyJDyyFc6 K+ng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si169625jao.29.2021.06.22.11.46.16; Tue, 22 Jun 2021 11:46:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232586AbhFVSrj (ORCPT + 99 others); Tue, 22 Jun 2021 14:47:39 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:51176 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbhFVSri (ORCPT ); Tue, 22 Jun 2021 14:47:38 -0400 Received: from [173.237.58.148] (port=33328 helo=localhost) by cloud48395.mywhc.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1lvlOj-0002Tj-Nx; Tue, 22 Jun 2021 14:45:21 -0400 Date: Tue, 22 Jun 2021 11:45:20 -0700 From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Olivier Langlois Message-Id: <67c806d0bcf2e096c1b0c7e87bd5926c37231b87.1624387080.git.olivier@trillion01.com> In-Reply-To: References: Subject: [PATCH 1/2] io_uring: Fix race condition when sqp thread goes to sleep X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cloud48395.mywhc.ca X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - trillion01.com X-Get-Message-Sender-Via: cloud48395.mywhc.ca: authenticated_id: olivier@trillion01.com X-Authenticated-Sender: cloud48395.mywhc.ca: olivier@trillion01.com X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If an asynchronous completion happens before the task is preparing itself to wait and set its state to TASK_INTERRUPTABLE, the completion will not wake up the sqp thread. Signed-off-by: Olivier Langlois --- fs/io_uring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index fc8637f591a6..02f789e07d4c 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6902,7 +6902,7 @@ static int io_sq_thread(void *data) } prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE); - if (!io_sqd_events_pending(sqd)) { + if (!io_sqd_events_pending(sqd) && !current->task_works) { needs_sched = true; list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { io_ring_set_wakeup_flag(ctx); -- 2.32.0