From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9641C4361B for ; Sun, 20 Dec 2020 13:59:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7906C22515 for ; Sun, 20 Dec 2020 13:59:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727514AbgLTN7i (ORCPT ); Sun, 20 Dec 2020 08:59:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25208 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726467AbgLTN7h (ORCPT ); Sun, 20 Dec 2020 08:59:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608472690; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ygmL3q/5ll9cPmj4O5J98mOLWYORoXLNBSNGUyVxYN4=; b=HtqpMG6PU5CaStv9KQICKgogecGqQfrsaiJdAWMIvEcfil7bM4pFQJHTprfQPyJdD8zhsY 7yk1ANaftS713jURmCImMI4kkqMaUTN+Rckf08a6s4FxWHDUkSFD7Gq6BAfdH8DaP2fwqX jFpnlJvrz7NMFYx4J8zYJsl8HimZTzw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-qLGM88QXPemeFrVfmyVfEA-1; Sun, 20 Dec 2020 08:58:08 -0500 X-MC-Unique: qLGM88QXPemeFrVfmyVfEA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E75BF1842141; Sun, 20 Dec 2020 13:58:06 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.40.192.9]) by smtp.corp.redhat.com (Postfix) with SMTP id 141E960C61; Sun, 20 Dec 2020 13:58:04 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 20 Dec 2020 14:58:06 +0100 (CET) Date: Sun, 20 Dec 2020 14:58:03 +0100 From: Oleg Nesterov To: Pavel Begunkov Cc: Al Viro , linux-kernel@vger.kernel.org, Jens Axboe Subject: Re: [RFC] exit: do exit_task_work() before shooting off mm Message-ID: <20201220135803.GA16470@redhat.com> References: <20201208013722.GG3579531@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/20, Pavel Begunkov wrote: > > On 08/12/2020 01:37, Al Viro wrote: > > On Thu, Dec 03, 2020 at 02:30:46AM +0000, Pavel Begunkov wrote: > >> Handle task works and lock it earlier before it starts killing off > >> task's resources like mm. io_uring makes use of it a lot and it'd > >> nicer to have all added task_work finding tasks in a consistent state. I too do not understand this patch. task_work_add() will fail after exit_task_work(). This means that, for example, exit_files() will use schedule_delayed_work(). > One more moment, after we've set PF_EXITING any task_work_run() would be > equivalent to exit_task_work() Yes, currently task_work_run() can not be called after exit_signals(). And shouldn't be called imo ;) > io_uring > may want (currently doesn't) to run works for cancellation purposes. Please see https://lore.kernel.org/io-uring/20200407163816.GB9655@redhat.com/ > Shouldn't it be like below (not tested)? Also simplifies task_work_run(). I'd prefer the patch from the link above, but your version looks correct too. However, I still think it would be better to not abuse task_work_run() too much... Oleg.