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 9C3E0C7EE2C for ; Fri, 25 Aug 2023 13:01:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242591AbjHYNBA (ORCPT ); Fri, 25 Aug 2023 09:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244860AbjHYNAx (ORCPT ); Fri, 25 Aug 2023 09:00:53 -0400 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DC691BE2 for ; Fri, 25 Aug 2023 06:00:50 -0700 (PDT) Received: from in01.mta.xmission.com ([166.70.13.51]:46396) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1qZWQj-008Bg8-BI; Fri, 25 Aug 2023 07:00:49 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:54132 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1qZWQh-003b2o-T9; Fri, 25 Aug 2023 07:00:48 -0600 From: "Eric W. Biederman" To: Linus Torvalds Cc: Oleg Nesterov , Andrew Morton , peterz@redhat.com, linux-kernel@vger.kernel.org References: <20230824143112.GA31208@redhat.com> Date: Fri, 25 Aug 2023 08:00:19 -0500 In-Reply-To: (Linus Torvalds's message of "Thu, 24 Aug 2023 08:02:51 -0700") Message-ID: <87y1hzs2e4.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1qZWQh-003b2o-T9;;;mid=<87y1hzs2e4.fsf@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/Fu5GH+AD9ivwUhyvPr8FDQlZtjWUgNIo= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH 0/2] introduce __next_thread(), change next_thread() X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus Torvalds writes: > On Thu, 24 Aug 2023 at 07:32, Oleg Nesterov wrote: >> >> After document-while_each_thread-change-first_tid-to-use-for_each_thread.patch >> in mm tree + this series > > Looking at your patch 2/2, I started looking at users ("Maybe we > *want* NULL for the end case, and make next_thread() and __next_thread > be the same?"). > > One of the main users is while_each_thread(), which certainly wants > that NULL case, both for an easier loop condition, but also because > the only user that uses the 't' pointer after the loop is > fs/proc/base.c, which wants it to be NULL. Sort of. I have found 3 loops that want to loop through all of the threads of a process starting with the current thread. The loop in do_wait. The loop finding the thread to signal in complete_signal. The loop in retarget_shared_pending finding which threads to wake up. For the signal case that is just quality of implementation, and starting somewhere else would just decrease that quality. For the loop in do_wait it is a correctness issue that the code starts first with the threads own children before looking for children of other threads. There are 4 users of next_thread outside of while_each_thread. - next_tid -- wants NULL - task_group_seq_get_next -- same as next_tid - __exit_signal -- wants any thread on the list after __unhash_process - complete_signal -- wants the same loop as do_wait. > And kernel/bpf/task_iter.c seems to *expect* NULL at the end? > > End result: if you're changing next_thread() anyway, please just > change it to be a completely new thing that returns NULL at the end, > which is what everybody really seems to want, and don't add a new > __next_thread() helper. Ok? So I would say Oleg please build the helper that do_wait wants and use it in do_wait, complete_signal, and retarget_shared_pending. Change the rest of the loops can use for_each_thread (skipping the current task if needed) or for_each_process_thread. Change __exit_signal to use signal->group_leader instead of next_thread. Change next_thread to be your __next_thread, and update the 2 callers appropriately. Eric