Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp741427pxj; Thu, 27 May 2021 10:32:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9qZzDpmJNAxFt3UGVNAJ7as6K04+LWr/z+V4C637ijs6c7eLvmidppbCLpkmcCUkI4RyP X-Received: by 2002:a05:6e02:11af:: with SMTP id 15mr3960695ilj.261.1622136729196; Thu, 27 May 2021 10:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622136729; cv=none; d=google.com; s=arc-20160816; b=OEYVHA/HUNY/+wLYAtBa3zCMyzQyUIFCr+7mIuWTuSGahR1jIXII9Ah6hsXLUO4pZ/ VeIPi0m54AjFmiXdKQmptU0Y7CJR1Hc6iTrEfZDFlDEjW/0xkE/UH+orAuqqujCjCQsU WtgrIBFEa25UmO1TdOxKADW67NXJ1fverNoptp9DeSAq3G5azUqxv9S6DyGc8y5u0dTT knLn87p89+sTk/JUpsoSuExds04IdEn2xSUcGRsBzYwNf/mlhXUcVfCbWr03yPRxuptS e33xvotQnXPDY7yK5Nh7I0ivIxnWnIKwIzh8mWiyG+JFfyg/boJegSfB4xMuEr83oMtZ sjlA== 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:to:from:subject :message-id; bh=K+pJxVFaNLw5mMT6+XO9ghtM9ho7gu9Dp73z1zA6e2k=; b=ZxzPd28G5cW8PyUXsVJnbuuNcbaFTNIsPK8awxJcat9v4BljIRPc35lUfRojPsr7BK TprDEteP7LTBl9anZfvBR8mWWnka1qbmt0CYfMr19fcF2KPgS3UkcDbC1wqu1z/hR41v 94Jauy+cIlRSULG83WEmt32jdr1thXzSY//6zrOsqUeWKhgjm7P8ETzTYslu9JO1Ts4m URMZegeTb9ThRCm2m69dQR/s8/QwMUFQe7C6dZTwWOT+zx8PS77MGzAYYok6ys86JQH7 nk+GLe77+94YR4ny/xbRR+QDaNzA0T5PNzIFCIPkeejhLPBLsyhrBgIqqTjG10bXJ5XK xymw== 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 k5si3114192ilv.81.2021.05.27.10.31.54; Thu, 27 May 2021 10:32:09 -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 S235506AbhE0PWn (ORCPT + 99 others); Thu, 27 May 2021 11:22:43 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:36896 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235017AbhE0PWn (ORCPT ); Thu, 27 May 2021 11:22:43 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:58504 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 1lmHor-0007mF-6e; Thu, 27 May 2021 11:21:09 -0400 Message-ID: <1e5c308bd25055ac8a899d40f00df08fc755e066.camel@trillion01.com> Subject: Re: [PATCH] io_uring: handle signals before letting io-worker exit From: Olivier Langlois To: Jens Axboe , Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 27 May 2021 11:21:08 -0400 In-Reply-To: <3d1bd9e2-b711-0aac-628e-89b95ff8dbc3@kernel.dk> References: <60ae94d1.1c69fb81.94f7a.2a35SMTPIN_ADDED_MISSING@mx.google.com> <3d1bd9e2-b711-0aac-628e-89b95ff8dbc3@kernel.dk> Organization: Trillion01 Inc Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.40.1 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 Thu, 2021-05-27 at 07:46 -0600, Jens Axboe wrote: > On 5/26/21 12:21 PM, Olivier Langlois wrote: > > This is required for proper core dump generation. > > > > Because signals are normally serviced before resuming userspace and > > an > > io_worker thread will never resume userspace, it needs to > > explicitly > > call the signal servicing functions. > > > > Also, notice that it is possible to exit from the io_wqe_worker() > > function main loop while having a pending signal such as when > > the IO_WQ_BIT_EXIT bit is set. > > > > It is crucial to service any pending signal before calling > > do_exit() > > Proper coredump generation is relying on PF_SIGNALED to be set. > > > > More specifically, exit_mm() is using this flag to wait for the > > core dump completion before releasing its memory descriptor. > > > > Signed-off-by: Olivier Langlois > > --- > > ?fs/io-wq.c | 22 ++++++++++++++++++++-- > > ?1 file changed, 20 insertions(+), 2 deletions(-) > > > > diff --git a/fs/io-wq.c b/fs/io-wq.c > > index 5361a9b4b47b..b76c61e9aff2 100644 > > --- a/fs/io-wq.c > > +++ b/fs/io-wq.c > > @@ -9,8 +9,6 @@ > > ?#include > > ?#include > > ?#include > > -#include > > -#include > > ?#include > > ?#include > > ?#include > > @@ -193,6 +191,26 @@ static void io_worker_exit(struct io_worker > > *worker) > > ? > > ????????kfree_rcu(worker, rcu); > > ????????io_worker_ref_put(wqe->wq); > > +???????/* > > +??????? * Because signals are normally serviced before resuming > > userspace and an > > +??????? * io_worker thread will never resume userspace, it needs > > to explicitly > > +??????? * call the signal servicing functions. > > +??????? * > > +??????? * Also notice that it is possible to exit from the > > io_wqe_worker() > > +??????? * function main loop while having a pending signal such as > > when > > +??????? * the IO_WQ_BIT_EXIT bit is set. > > +??????? * > > +??????? * It is crucial to service any pending signal before > > calling do_exit() > > +??????? * Proper coredump generation is relying on PF_SIGNALED to > > be set. > > +??????? * > > +??????? * More specifically, exit_mm() is using this flag to wait > > for the > > +??????? * core dump completion before releasing its memory > > descriptor. > > +??????? */ > > +???????if (signal_pending(current)) { > > +???????????????struct ksignal ksig; > > + > > +???????????????get_signal(&ksig); > > +???????} > > ????????do_exit(0); > > ?} > > Do we need the same thing in fs/io_uring.c:io_sq_thread()? > Jens, You are 100% correct. In fact, this is the same problem for ALL currently existing and future io threads. Therefore, I start to think that the right place for the fix might be straight into do_exit()...