Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5919682pxj; Wed, 23 Jun 2021 11:52:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylpJPb1JGxIcQ8r2pW91ETkuBUx9ypuFRjd2MxwqhCUosM2xRcSaIQyFeDi4/U8ZVE7KC/ X-Received: by 2002:a05:6638:109:: with SMTP id x9mr951053jao.85.1624474340374; Wed, 23 Jun 2021 11:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624474340; cv=none; d=google.com; s=arc-20160816; b=yowB/6F0HamhqDT0ZpJ0+Va7nRKej6A9H4ZJt56wDipyQp2xx7dmQsoZWjkWLsmqNL bd2IyhtGyxleJ2CZEjT0InSxGWjenEB399pKXToZ/H3pLHm/gVnLBqXtw6iyi08wq3GC OrSPz2KbYJWVYKPgKTw9L7AIR2019is0qldFCxqWvrzHyWSj+Hmc7qnV/up7qRAQVBPX 2WdsrgHOy+3BKjTE6X9v8R0D1gaz6vSXJaHR2X3Q8b8+lylUtILRjSCddWu0/WL2YwrA ITVW+jiFEiBOizJc4SojfatKjAutHtNe2KRFh92zU/wRUFfWzkqCH3A3K3Ptbh03WKvn oejw== 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=MULeCjVEMdtPHVs4GdUoH5T3MVX54xKS0O1MfWNIrm4=; b=Md9yxw5/fs4Ch2604S1aGMnQ+PDwzIrnGkb9NTAT8IohdK6ipRMCYwSEk/Z2lkq6UB Fn7478XK6TqzXIR0+lxrtsx41HMkuq99wgI6UXdvSTDBTkoPO7uAui4aXABbkEwcqapH popXavcURJXSlHT0iPHbdYkGKfLF00aGMUZgZ0juBifh23+X+QxDau+Aw6GpEltepo0Z nJ8lF1/ZvXCE0O0toGei2GxXvdv+ZsLjnjwLqpmwVhnEJm7ex+/+gV77WyntRj0e5v9b MYY/J369G3C1eqXiPtzV23hCVCu9metUGu3qR/nM1JseA2iF0mfhLi8BmykWDWf0Kyr7 pK7Q== 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 a3si688690jam.62.2021.06.23.11.52.08; Wed, 23 Jun 2021 11:52:20 -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 S229945AbhFWSwd (ORCPT + 99 others); Wed, 23 Jun 2021 14:52:33 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:41016 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbhFWSwc (ORCPT ); Wed, 23 Jun 2021 14:52:32 -0400 Received: from [173.237.58.148] (port=33336 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 1lw7wy-0008Hi-MX; Wed, 23 Jun 2021 14:50:12 -0400 Date: Wed, 23 Jun 2021 11:50:11 -0700 From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Olivier Langlois Message-Id: In-Reply-To: References: Subject: [PATCH v2 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_INTERRUPTIBLE, 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..7c545fa66f31 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) && !io_run_task_work()) { needs_sched = true; list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { io_ring_set_wakeup_flag(ctx); -- 2.32.0