Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5040376pxj; Tue, 22 Jun 2021 13:46:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzNa1Mtgdi9o5+gE0NdVBWDDyt0VY38np2dcIjFbK9OjD/P0QHLCgdA65Ax3zbfGtrikSwI X-Received: by 2002:a50:b2c5:: with SMTP id p63mr7579652edd.5.1624394796903; Tue, 22 Jun 2021 13:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624394796; cv=none; d=google.com; s=arc-20160816; b=Jc00cVsW961juWUT4g/agCDUiIl+AC3Kw4pnT+HFeV+w11iuHTnPdkCztMkY010ESU Vu1sQPXGs0OS1FQLoQgFcIXqfBli0i8An3zag6y6a+ECf3iD4abX2/wKQ28XUksnJ3t4 9hI2qQZC4nvhCC6B+xVmpLR4Wsm6bF4tmI/B23v8FSNTTUYUy6wNDeIafuZo3Wm6RHQG yVFkKAqk2Vx28b6lBNMFSqwlBZq94VkDDwRDN48NyZyDNoBIjTIJ2mK1XZ0Vx7QdGdCQ U6YNTqqL9lcf1CV2FXRRFFUPc9F8EeVw9hE1M9Ek7QiqCcyG9Nwe/pamGA1P5bGvYk/b KfPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:to:dkim-signature; bh=oJKHAUVoWMvgZKaBkUowP7jbYxwJkBTpJAJrtLjjKQk=; b=Q69YdxT00vfhtbuiTALWqHc0LvzeWQMU55UTL4iVf4oTOPIOuIsmXqlR75okQkKz3+ 2Cko/q5jWTq6J/p4ELx9Fal6Obf5Ax1c+MJepLgruGyqmkoNoos3Yjua5gGnPIKISKui hGXwlOMnmwqu9py2YgeLqs/EU7gvIlUU0xh1RDIFmPpCjBgDbBnuEXH5dq+NTJ4cSAuK QcRhQvfeEcP3oeG4ifIBTLpZZ2HNfhia1ek6ulXbtjgkBFsb34emArR77L3vIob892lh VSjJCGlYNTZQgBRgFCU2Lc5lqi5+yrIMiw4JFQs+fB4uVNcXK9y0o4IUx42tXmfV6Bf+ Y2kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p7yWCBJM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b10si16165726ejj.523.2021.06.22.13.46.11; Tue, 22 Jun 2021 13:46:36 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=p7yWCBJM; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229718AbhFVUre (ORCPT + 99 others); Tue, 22 Jun 2021 16:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbhFVUre (ORCPT ); Tue, 22 Jun 2021 16:47:34 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC509C061574; Tue, 22 Jun 2021 13:45:16 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id n7so158680wri.3; Tue, 22 Jun 2021 13:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:references:from:subject:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=oJKHAUVoWMvgZKaBkUowP7jbYxwJkBTpJAJrtLjjKQk=; b=p7yWCBJM6f2Q0GP/YKsRi5+XPpTdu9Aa3H9rDSEH+e5NQ4y5//2txanDgqHnlQ4wmc Sw3Oe+OvmniZmYA0/hxMGuNvzpgKg/S7jbflsKvqfIBnc7vcQLWZ2ehaaxKvrqiXAFu9 s4KCBxGZ9ZyjMZbwO09Fq2Ohw0u76FKuySaAuRrp/BTRmGYTpzINuSoxsglzpJbUnl4j Jk8lHexWtj4iauR+TJ3i2bA1dUSggAlhObx6VxZpE2AF+IUw9htYbPGvJNtC+t/Nh5ji Tm1SBNqLCh84eRpxWQXzvMpwaa6QJ3+gxKoRq8PsbFKHAIvmCq8raRrxLMcnkoVcZbB6 AHIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=oJKHAUVoWMvgZKaBkUowP7jbYxwJkBTpJAJrtLjjKQk=; b=tbn9ImiQn/O8frlGyl1xD935GUOD/fIJpXNtnrgRwlKJinAvZyYKGZOKOtJZZ7VWw6 09Fs/NvyUJ5FQLMQo7ZawE6dSXnxqkUk8u7/VC5FYYrV0byUrwYzTKtRSo6dN1CQ0mUN aIUhbWodMkoDKVZc+tIfeanKBSbP4EzYny5sSayP8gaHgL2FR1sWAUDUtu5c9m3MUS0f htqwIOLaPA7dqR5Is32bthw8AOoXraKwj8IZBizK6kbJ3NN9RVtREReNuSZLwXtDXxVa TlJiJ89F8Yu0CwvKxlwiKGtCBw9gPtNki3GjctkDM/PZvkEwg/jgE56UD73qCM4TmZ8J 3mxw== X-Gm-Message-State: AOAM530+c6WrDem8kGpw//H5Yj7pvlms/Agkp3DwriZDaeMlmdv5GIT7 vWwUG51GtDgVV4YkSr3QGTZgpBCty2rIqhZe X-Received: by 2002:a05:6000:1c1:: with SMTP id t1mr7151808wrx.282.1624394715000; Tue, 22 Jun 2021 13:45:15 -0700 (PDT) Received: from [192.168.8.197] ([148.252.132.93]) by smtp.gmail.com with ESMTPSA id q19sm3394293wmc.44.2021.06.22.13.45.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 13:45:14 -0700 (PDT) To: Olivier Langlois , Jens Axboe , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <67c806d0bcf2e096c1b0c7e87bd5926c37231b87.1624387080.git.olivier@trillion01.com> <60d23218.1c69fb81.79e86.f345SMTPIN_ADDED_MISSING@mx.google.com> From: Pavel Begunkov Subject: Re: [PATCH 1/2 v2] io_uring: Fix race condition when sqp thread goes to sleep Message-ID: Date: Tue, 22 Jun 2021 21:45:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <60d23218.1c69fb81.79e86.f345SMTPIN_ADDED_MISSING@mx.google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/21 7:55 PM, Olivier Langlois wrote: > 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..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) { Agree that it should be here, but we also lack a good enough task_work_run() around, and that may send the task burn CPU for a while in some cases. Let's do if (!io_sqd_events_pending(sqd) && !io_run_task_work()) ... fwiw, no need to worry about TASK_INTERRUPTIBLE as io_run_task_work() sets it to TASK_RUNNING. > needs_sched = true; > list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) { > io_ring_set_wakeup_flag(ctx); > -- Pavel Begunkov