Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3164547pxt; Mon, 9 Aug 2021 19:09:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzi6caNGzB0g4yFDDbFuVC/dyemmO3GMfmQrh7UTELpnGOPMEqvXeEL9/3yUbjvNB/rN3GR X-Received: by 2002:a17:906:4c8c:: with SMTP id q12mr25834289eju.254.1628561344875; Mon, 09 Aug 2021 19:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628561344; cv=none; d=google.com; s=arc-20160816; b=i5037917y9pEMWjVvPy0UWNWrRWvwy6D1hmeraN33LDq13NHKYg3rc5WjyM1n6boCB CjyqD3iOtDaaIk4/KpIyx0Bk7ta15yKJN72zXKkjJ1NfaKdok3lGiy8UMdqlU3KV7F3S VqqQiftHWrBrDziWiUhKcC0EGAi2kmLXqAjWZYNFunO5EJfj+ZFZsDfDN+rQpS5i1oS2 AwHbSkTacUC4TxXRjcGOBNn4vetVuxeRR1d/cm3kGwOr+iYGzkPYzFPuD/48yM1qvEuC 1GfWtMMAHUodgP43EMApFuAptyT0sIQMPzB7By4+5RSHDuVFhZs4TsuVFlPzve6A2C30 I/OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=FeLvt7VfChkZER0h0gVlw667kt1L+KlnF4gG5OfJne8=; b=z1+YiwdJoEdifOUZurID9shnzojtZxSvV3lYDHGDOKQRkppSC5hqzCDJs3fg5Ijf2h 0y2tMFJqHQ4bFx7t6F24uT6u/0hyXhy0Pzdg7bP/5FBt62UCFQxzc3mZ5wJ6PUqsuulY E6AA1OxKcBLT7vWljJVA0egcYgRw9PWVJixE4b90zyvkL/rHuVA6SOvcAOjSfAZombIe eGfho4u1hTJnr9cqx/ihqk/Jd1az1y/upIb9Gc18C/LhKhrY9pH8Kd0ivi5Rt2RATHdp z3jQ1o7Gf/t/En5BJATZyj87/aHLYU8/HMLW9Z8nool0ZCwHSERmYB29L0UWWTNOWm6B XRDg== 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 b10si20317956edm.341.2021.08.09.19.08.24; Mon, 09 Aug 2021 19:09:04 -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 S235860AbhHIVtB (ORCPT + 99 others); Mon, 9 Aug 2021 17:49:01 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:45308 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233294AbhHIVtB (ORCPT ); Mon, 9 Aug 2021 17:49:01 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:54436 helo=[192.168.1.179]) by cloud48395.mywhc.ca with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mDD8R-0005EU-6B; Mon, 09 Aug 2021 17:48:39 -0400 Message-ID: Subject: Re: [PATCH 1/2] io_uring: clear TIF_NOTIFY_SIGNAL when running task work From: Olivier Langlois To: Nadav Amit , Jens Axboe Cc: io-uring@vger.kernel.org, linux-kernel@vger.kernel.org, Nadav Amit , Pavel Begunkov Date: Mon, 09 Aug 2021 17:48:38 -0400 In-Reply-To: <20210808001342.964634-2-namit@vmware.com> References: <20210808001342.964634-1-namit@vmware.com> <20210808001342.964634-2-namit@vmware.com> Organization: Trillion01 Inc Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 On Sat, 2021-08-07 at 17:13 -0700, Nadav Amit wrote: > From: Nadav Amit > > When using SQPOLL, the submission queue polling thread calls > task_work_run() to run queued work. However, when work is added with > TWA_SIGNAL - as done by io_uring itself - the TIF_NOTIFY_SIGNAL remains > set afterwards and is never cleared. > > Consequently, when the submission queue polling thread checks whether > signal_pending(), it may always find a pending signal, if > task_work_add() was ever called before. > > The impact of this bug might be different on different kernel versions. > It appears that on 5.14 it would only cause unnecessary calculation and > prevent the polling thread from sleeping. On 5.13, where the bug was > found, it stops the polling thread from finding newly submitted work. > > Instead of task_work_run(), use tracehook_notify_signal() that clears > TIF_NOTIFY_SIGNAL. Test for TIF_NOTIFY_SIGNAL in addition to > current->task_works to avoid a race in which task_works is cleared but > the TIF_NOTIFY_SIGNAL is set. > > Fixes: 685fe7feedb96 ("io-wq: eliminate the need for a manager thread") > Cc: Jens Axboe > Cc: Pavel Begunkov > Signed-off-by: Nadav Amit > --- > ?fs/io_uring.c | 5 +++-- > ?1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/fs/io_uring.c b/fs/io_uring.c > index 5a0fd6bcd318..f39244d35f90 100644 > --- a/fs/io_uring.c > +++ b/fs/io_uring.c > @@ -78,6 +78,7 @@ > ?#include > ?#include > ?#include > +#include > ? > ?#define CREATE_TRACE_POINTS > ?#include > @@ -2203,9 +2204,9 @@ static inline unsigned int io_put_rw_kbuf(struct > io_kiocb *req) > ? > ?static inline bool io_run_task_work(void) > ?{ > -???????if (current->task_works) { > +???????if (test_thread_flag(TIF_NOTIFY_SIGNAL) || current->task_works) > { > ????????????????__set_current_state(TASK_RUNNING); > -???????????????task_work_run(); > +???????????????tracehook_notify_signal(); > ????????????????return true; > ????????} > ? thx a lot for this patch! This explains what I am seeing here: https://lore.kernel.org/io-uring/4d93d0600e4a9590a48d320c5a7dd4c54d66f095.camel@trillion01.com/ I was under the impression that task_work_run() was clearing TIF_NOTIFY_SIGNAL. your patch made me realize that it does not...