Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2943977pxv; Sun, 25 Jul 2021 10:49:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzsaZJ+4lbRZ6jMfDBMjmPrOLZquepFWp7djpWbI8KzKPZIS65+k55rHehUItnDx/Z7ZW2L X-Received: by 2002:a05:6402:202f:: with SMTP id ay15mr17028698edb.147.1627235384362; Sun, 25 Jul 2021 10:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627235384; cv=none; d=google.com; s=arc-20160816; b=Wwbt1XajSB9/0GUbVBvkD9GBa1THc019xixUddEe5e7efYj449j4NoPwfogo8leI21 XhVpCvq6S/+vNClIsHZYv3WLosiQ8AEEs1j9gACE1yJCVStVLt7mebwSMxXoFjiKoK5Y BRMoVHJU65sSyfFodBMlnaI/VCfGqYDTzhB2mnv3iJAIoduece5h02sHs/Im19KGRUXH e9XOGjyMxWoDcIzAaJqzsvphCgJK/vnW+lWWEMR8N2J7g0t5UW11E95r2HpwL3Wsghsx OVv52LAEsaMumB2XsI2b8IdvtDOnKUbsunHe2XHAN/ycbSOve8h/NSOZx8AMKM7Tp5Zt AtZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:date:to:from:message-id; bh=fMQ/wgszvRiFW/v7hevcEMQ+mF7Agwo/iJGz6AiNXHc=; b=ZYXAfP498rqle+fUah6uFRMFHLumTbC+lWuu8YbwOOl6CapHqVsza4mtAG+OUN6G6D 9WQrmZRWxsGPy4yQ411FuAtfHce9YOGEi/WESyIhosxt8gWJJmo3zotxCjXBoTGm0iIc yD9lxNgk9IdT8hpMqzEk18SButDzvPLkYbFfW2t3+oKXSrnuv5g8FfkPjl5DRGiXTLjz KxJQQH9067Zv7VTZA+4zcDI5utlG73mm7zxUORDGDlyIFCGftnUkW9KDOx8a/2Eu8v4D 8jaaRR/fjgGLXX8Oe74on+rR7X7G0/z+Er+T59ZTNTIsxJErUh+8AmK5HFTQStc3SYvy 3NAw== 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 i1si3508145edj.267.2021.07.25.10.49.07; Sun, 25 Jul 2021 10:49:44 -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 S231278AbhGYREL (ORCPT + 99 others); Sun, 25 Jul 2021 13:04:11 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:41268 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbhGYREL (ORCPT ); Sun, 25 Jul 2021 13:04:11 -0400 Received: from [173.237.58.148] (port=51036 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 1m7iB5-0004MM-GM; Sun, 25 Jul 2021 13:44:39 -0400 Message-Id: <82a82077d8b02166482df754b1abb7c3fbc3c560.1627189961.git.olivier@trillion01.com> From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, gregkh@linuxfoundation.org Date: Sat, 24 Jul 2021 22:07:59 -0700 Subject: [PATCH io_uring backport to 5.13.y] 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 [ Upstream commit 997135017716 ("io_uring: Fix race condition when sqp thread goes to sleep") ] 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index eeea6b8c8bee..a7f1cbd7be9a 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -6876,7 +6876,8 @@ static int io_sq_thread(void *data) } prepare_to_wait(&sqd->wait, &wait, TASK_INTERRUPTIBLE); - if (!test_bit(IO_SQ_THREAD_SHOULD_PARK, &sqd->state)) { + if (!test_bit(IO_SQ_THREAD_SHOULD_PARK, &sqd->state) && + !io_run_task_work()) { list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) io_ring_set_wakeup_flag(ctx); -- 2.32.0