Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp742137pxj; Thu, 27 May 2021 10:32:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrT1DCQDWHEOEJme3DIutIWcUOrJP1yqHv7iofhvKrFQskRjBijNF4ZNjBFDmv3O4GSSlQ X-Received: by 2002:a05:6e02:2141:: with SMTP id d1mr4077735ilv.190.1622136773379; Thu, 27 May 2021 10:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622136773; cv=none; d=google.com; s=arc-20160816; b=Mf4Jp8S6iKE1V4mK5VB1u4+q0wj59cIPhV3dtCcPy6w21M6ORHiuR0csOFv5+bMFM6 VhZKXKJBVSflHHO/l1nt3/uM3Mm0kbdsjCa03U2DLEtAWzAz2zRWmXs0NrKKRCDb+HNZ +h2wvRbocToIt0fUgM9lZBpKfYLr92J1p4GOlOIRmRg0JI7NkWJc8XPUuhRvo6T2BHy1 zrc8kEji0dQYX6sNN8RImdWdHsZ6lFXmzbSExtfgNsOgj9UgPWwn2UrQO0djx2ucXnt+ aoo+s/VVWk+2R25vKwlS5yYtGlQX3/dUndb59cE9/O9c0lPVX13uIlAwWkhp5uF7z3k0 X/eg== 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:from:references :to:subject:dkim-signature; bh=8Op4gnoaksdh+U4uxBaqZw6x+/2lPI5nN0JuZIQFbB8=; b=kZQNrOZH7hAdDjcYxpZ9+bgrSPqs7sv+VgSRmRmXe8f1bxKawUqtOSBsq9ObJ5pegb 6qND+F8hObUaauuU2wfyci6j0xcjwQdYhBLFM3CjZ+vFysjNmdeNgFH1M1pTe+/ExrZ9 DL1hnl8EsSNE3XTLZVum9BhkD7pnCxQCPmgLQ7saWPlRqx7J5E1iLQ3BubBzgWGVIfVL y05pRtqYsdqJ9cb2NKPXISwn6o0PsEA63NUaLI9yeDleUyTD9LR60ncQ9CSzdCdXQPGf nKtlJWi0ItmxMAHxA5Wt4d7u8afG73qqZx2haNeQmAV6MmCGQb6Ta29L1cHNuZ+QDyad G+Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=ftbzGVXV; 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 i9si2878716ils.148.2021.05.27.10.32.38; Thu, 27 May 2021 10:32:53 -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=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=ftbzGVXV; 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 S236025AbhE0Pbw (ORCPT + 99 others); Thu, 27 May 2021 11:31:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235395AbhE0Pbt (ORCPT ); Thu, 27 May 2021 11:31:49 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85E83C061760 for ; Thu, 27 May 2021 08:30:16 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id z3so1141817oib.5 for ; Thu, 27 May 2021 08:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=8Op4gnoaksdh+U4uxBaqZw6x+/2lPI5nN0JuZIQFbB8=; b=ftbzGVXVapQHfjABpJplpIhe9rGYm/CFIzFI1r7uc4HRf8hXK5qre6sTQzNf8MHREw HNJHRp8vmCtTbn3s6cKFePNAhTQD3r7wtXcFMj6UWu8rlKfOWHE1VSMmGZlmdtse5mci 7Sv7XhR7mtmgLMoim9CJH413G41rwl39cGJeYZYNPLDliRv18tUc3FhTq81zjJevzZ4H SK2TXYIVxyDLpZX2VZxqyeENnH7dr3HqejjFhlDTPbJZ4MRy6ZidlxgDaPMD0IuAiDAn Lnj4FAubI8vbgAhBh2+K9bAuebv8X+wCZTGipWVUYM2hwAtNx+PnLRVCRWmV8cjDFEPw gk7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8Op4gnoaksdh+U4uxBaqZw6x+/2lPI5nN0JuZIQFbB8=; b=I3AxKVMd9SzgIEGV4KobEniA5+wvIrCZeCdkq/EYDw0QQ/LuyDJhsf2xsXqoQH0i7v UJ+5QKXVt4RjkYqTfALTbl/aI9A6x3BdDxmMUsKWQEcRi9HsZKULWlX1oWisISPq8/eh NQVNvmfsic5jv/pGJ3QzUfodHRObVf7ou9MARqif5rCuuNqPrPocBPa5qK1Zndw7u9O/ M/CMEBVDb662witjHJMoFcPOQvg9Xc5hNhZV6IS01VGyzlGTLSQR9dhnTvjINPaG3kjT /ZlSXBby49+EgpvyLTTjFuGqLINFEiijGTNbuoJcVEA9aK1Ph4wRfVnyt+LpOJOk4v4Z TyQg== X-Gm-Message-State: AOAM530I8Uw2JwOWg4z88UczewcC6cL6iKKL6Tfn1IVN39q57iXIRsA6 K3XeSr3kCORIMcivgpLrCUuXUXoNC3WyPA== X-Received: by 2002:a54:4e10:: with SMTP id a16mr6051687oiy.48.1622129415549; Thu, 27 May 2021 08:30:15 -0700 (PDT) Received: from [192.168.1.30] ([207.135.233.147]) by smtp.gmail.com with ESMTPSA id t39sm476798ooi.42.2021.05.27.08.30.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 27 May 2021 08:30:15 -0700 (PDT) Subject: Re: [PATCH] io_uring: handle signals before letting io-worker exit To: Olivier Langlois , Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: <60ae94d1.1c69fb81.94f7a.2a35SMTPIN_ADDED_MISSING@mx.google.com> <3d1bd9e2-b711-0aac-628e-89b95ff8dbc3@kernel.dk> <1e5c308bd25055ac8a899d40f00df08fc755e066.camel@trillion01.com> From: Jens Axboe Message-ID: <7e10ffd2-5948-3869-b0dc-fd81d693fe33@kernel.dk> Date: Thu, 27 May 2021 09:30:14 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <1e5c308bd25055ac8a899d40f00df08fc755e066.camel@trillion01.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/27/21 9:21 AM, Olivier Langlois wrote: > 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()... That is what I was getting at. To avoid poluting do_exit() with it, I think it'd be best to add an io_thread_exit() that simply does: void io_thread_exit(void) { if (signal_pending(current)) { struct ksignal ksig; get_signal(&ksig); } do_exit(0); } and convert the do_exit() calls in io_uring/io-wq to io_thread_exit() instead. -- Jens Axboe