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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50916C83F15 for ; Sat, 26 Aug 2023 20:29:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229739AbjHZU24 (ORCPT ); Sat, 26 Aug 2023 16:28:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjHZU2x (ORCPT ); Sat, 26 Aug 2023 16:28:53 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50EE7CF1 for ; Sat, 26 Aug 2023 13:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=GQbLFOOBAbkQ+pMFo1tY5HOEbzfs6NK86EY1TrLGlT8=; b=LdYwvMXrpVavNV7//q6Vty51Hq OCPautXtKdR3XtxES41NiGunhEyaALsAfzGwvQ2cv5td32/RwX4nSr1wX9xAS+yUTbgveMc6krFr5 KPZ+3+r+SKOa9ezWPDfjo7u/MmjI184tNuRRgwoBmS/UoVUQDha+tMVeWoBHUZ4KxSxknoZyus8rM 7yZ+jOGT/G/DD0emJyEe7Pj1UbyUJ0LYP59u2Ha3n4BZDHvX8uPkpCI/Q+O/cDoAj403dSc7m/WPs 1L2G1gQcIObJfkqyNUmf5GxGO7wUfAH43NnYGZy2mvjhy5dWY6q3Ms0YtBB0ykWH9agvBpIGXdQS7 5Pvz4hlw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qZztE-007aFb-MY; Sat, 26 Aug 2023 20:28:12 +0000 Date: Sat, 26 Aug 2023 21:28:12 +0100 From: Matthew Wilcox To: Tong Tiangen Cc: Naoya Horiguchi , "Paul E. McKenney" , Andrew Morton , Naoya Horiguchi , Miaohe Lin , wangkefeng.wang@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: memory-failure: use rcu lock instead of tasklist_lock when collect_procs() Message-ID: References: <20230821091312.2034844-1-tongtiangen@huawei.com> <0bbbb7d8-699b-30ac-9657-840112c41a78@huawei.com> <20230825060221.GA3948311@ik1-406-35019.vs.sakura.ne.jp> <9e205429-1f27-4d18-faca-8a4fe9d429e3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e205429-1f27-4d18-faca-8a4fe9d429e3@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Aug 26, 2023 at 09:46:53AM +0800, Tong Tiangen wrote: > " the ``task_struct`` object is freed only after one or more > grace periods elapse, with the help of call_rcu(), which is invoked via > put_task_struct_rcu_user(). " > > Combined with the code,when the task exits: > > release_task() > __exit_signal() > __unhash_process() > list_del_rcu(&p->tasks) > > put_task_struct_rcu_user() > call_rcu(&task->rcu, delayed_put_task_struct); > > delayed_put_task_struct() > put_task_struct() > if (refcount_sub_and_test(nr, &t->usage)) > __put_task_struct() > free_task() > > The code is consistent with the description in the document. > > According to this understanding, i think for_each_process() under the > protection of rcu locl is safe, that is, task_struct in the list will not be > destroyed, and get_task_struct() is also safe. Aha! This is different from the usual pattern. What I'm used to seeing is: if (refcount_sub_and_test()) { list_del_rcu(); rcu_free(); } and then on the read side you need a refcount_inc_not_zero(), which we didn't have here. Given this new information you've found, I withdraw my objection. It'd be nice to include some of this analysis in an updated changelog (and maybe improved documentation for tasklist?).