Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp769550pxj; Thu, 27 May 2021 11:11:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx26Xbm6lQ3uHdahyGp+WpFiyyg7TijRMm9KegelpNHiNPdwRndmSgF98sJMvDFeHZ9HpTx X-Received: by 2002:a50:d589:: with SMTP id v9mr5772285edi.126.1622139085859; Thu, 27 May 2021 11:11:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622139085; cv=none; d=google.com; s=arc-20160816; b=s/3AU4yAGgURuifewrRBM57NXqcSU73bGpFMoAnVZCpiNTDs+Qdm5dlzSqWIYga3eA Kp3SL3ETmnTxN4jH1k+xZWJqkBCtKCQEOXJEnyEhX1vhr/9HmnETDrmuPxQ6pNy9PGFW GGqsn0uk1x1CgSUdmCfl1WD7hmaDjLUU/6k9jKGylWE3eQ1ykS/RVJhk7/C68ssYs79H D9gJPFmpBFQ5VzNIL+bAECuMFYAdFFE6Iem3K5u4HK2oEjhDH7AhxReJHlKl6t+DNhrE dJ2E2cDfRikJlONwL+J3a7EJIcK85b89+dCNbEwbrUuwt2kenDZh7EtPNKzGL+4n5Npt L35Q== 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=QZGcfNcft7m5zwzvsmd3Zevot+WuzDyoNvARZ3fyulU=; b=uOmSK7cw1i/XT9wgP6B6RGT5nV2H9x6Snis5Sqwv3RHyxRxI5J3EBc0fnzIYpgVOix 4JtFepdy99gS15wq4fc74SIYHt8kwmOeL7tqriD+dzN9iqP8eewgFHCu27XA7Df/4Chs /E5eY1pdRJEG5hq7tgJ63+KoiW3mA/jlxwDqlVpCR3d5H1LWGsgwcsvgKenWdM9XTFJ/ U2GZm0JeHeNtA4QysfHlumF6TysUpUcz2oujFzeZUSn3bvMAL/tjpgxpF14gOn+hSj9b P3+IWE01gLYY4TxTqC80oUp7Muv8rstJ4hGUeCtQHdMES6oZTdPyiJXqWvOdlWoHuNt9 ping== 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 a24si2662795edu.170.2021.05.27.11.11.01; Thu, 27 May 2021 11:11:25 -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 S235528AbhE0QLX (ORCPT + 99 others); Thu, 27 May 2021 12:11:23 -0400 Received: from cloud48395.mywhc.ca ([173.209.37.211]:53278 "EHLO cloud48395.mywhc.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233839AbhE0QLV (ORCPT ); Thu, 27 May 2021 12:11:21 -0400 Received: from modemcable064.203-130-66.mc.videotron.ca ([66.130.203.64]:58506 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 1lmIZv-0001O5-GO; Thu, 27 May 2021 12:09:47 -0400 Message-ID: <6b67bd40815f779059f7f3d3ad22f638789452b1.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 12:09:46 -0400 In-Reply-To: <7e10ffd2-5948-3869-b0dc-fd81d693fe33@kernel.dk> References: <60ae94d1.1c69fb81.94f7a.2a35SMTPIN_ADDED_MISSING@mx.google.com> <3d1bd9e2-b711-0aac-628e-89b95ff8dbc3@kernel.dk> <1e5c308bd25055ac8a899d40f00df08fc755e066.camel@trillion01.com> <7e10ffd2-5948-3869-b0dc-fd81d693fe33@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 09:30 -0600, Jens Axboe wrote: > > > > > 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. > IMHO, that would be an acceptable compromise because it does fix my problem. However, I am of the opinion that it wouldn't be poluting do_exit() and would in fact be the right place to do it considering that create_io_thread() is in kernel and theoritically, anyone can call it to create an io_thread and would be susceptible to get bitten by the exact same problem and would have to come up with a similar solution if it is not addressed directly by the kernel. Also, since I have submitted the patch, I have made the following realization: I got bitten by the problem because of a race condition between the io- mgr thread and its io-wrks threads for processing their pending SIGKILL and the proposed patch does correct my problem. The issue would have most likely been buried by 5.13 io-mgr removal... BUT, even the proposed patch isn't 100% perfect. AFAIK, it is still possible, but very unlikely, to get a signal between calling signal_pending() and do_exit(). It might be possible to implement the solution and be 100% correct all the time by doing it inside do_exit()... I am currently eyeing exit_signals() as a potential good site for the patch...