From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8795D1864D for ; Fri, 27 Oct 2023 12:04:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=none Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [IPv6:2a0a:edc0:2:b01:1d::104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB58C0 for ; Fri, 27 Oct 2023 05:04:35 -0700 (PDT) Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qwLZp-0001Rd-Fa; Fri, 27 Oct 2023 14:04:33 +0200 Received: from [2a0a:edc0:2:b01:1d::c0] (helo=ptx.whiteo.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qwLZo-004d6Z-Dy; Fri, 27 Oct 2023 14:04:32 +0200 Received: from sha by ptx.whiteo.stw.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1qwLZo-00Gbnc-Ai; Fri, 27 Oct 2023 14:04:32 +0200 Date: Fri, 27 Oct 2023 14:04:32 +0200 From: Sascha Hauer To: Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S . Miller" , Jakub Kicinski , Jens Axboe , kernel@pengutronix.de Subject: Re: [PATCH] net: Do not break out of sk_stream_wait_memory() with TIF_NOTIFY_SIGNAL Message-ID: <20231027120432.GB3359458@pengutronix.de> References: <20231023121346.4098160-1-s.hauer@pengutronix.de> <20231026070310.GY3359458@pengutronix.de> <8404022493c5ceda74807a3407e5a087425678e2.camel@redhat.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8404022493c5ceda74807a3407e5a087425678e2.camel@redhat.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org On Thu, Oct 26, 2023 at 10:49:18AM +0200, Paolo Abeni wrote: > On Thu, 2023-10-26 at 09:03 +0200, Sascha Hauer wrote: > > On Tue, Oct 24, 2023 at 03:56:17PM +0200, Paolo Abeni wrote: > > > On Mon, 2023-10-23 at 14:13 +0200, Sascha Hauer wrote: > > > > It can happen that a socket sends the remaining data at close() time. > > > > With io_uring and KTLS it can happen that sk_stream_wait_memory() bails > > > > out with -512 (-ERESTARTSYS) because TIF_NOTIFY_SIGNAL is set for the > > > > current task. This flag has been set in io_req_normal_work_add() by > > > > calling task_work_add(). > > > > > > > > It seems signal_pending() is too broad, so this patch replaces it with > > > > task_sigpending(), thus ignoring the TIF_NOTIFY_SIGNAL flag. > > > > > > This looks dangerous, at best. Other possible legit users setting > > > TIF_NOTIFY_SIGNAL will be broken. > > > > > > Can't you instead clear TIF_NOTIFY_SIGNAL in io_run_task_work() ? > > > > I don't have an idea how io_run_task_work() comes into play here, but it > > seems it already clears TIF_NOTIFY_SIGNAL: > > > > static inline int io_run_task_work(void) > > { > > /* > > * Always check-and-clear the task_work notification signal. With how > > * signaling works for task_work, we can find it set with nothing to > > * run. We need to clear it for that case, like get_signal() does. > > */ > > if (test_thread_flag(TIF_NOTIFY_SIGNAL)) > > clear_notify_signal(); > > ... > > } > > I see, io_run_task_work() is too late, sk_stream_wait_memory() is > already woken up. > > I still think this patch is unsafe. What about explicitly handling the > restart in tls_sw_release_resources_tx() ? The main point is that such > function is called by inet_release() and the latter can't be re- > started. I don't think there's anything I can do in tls_sw_release_resources_tx(). When entering this function TIF_NOTIFY_SIGNAL is not (yet) set. It gets set at some point while tls_sw_release_resources_tx() is running. I find it set when tls_tx_records() returns with -ERESTARTSYS. I tried clearing TIF_NOTIFY_SIGNAL then and called tls_tx_records() again, but that doesn't work. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |