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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 215DAC433E9 for ; Wed, 10 Mar 2021 22:13:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F28A564FDA for ; Wed, 10 Mar 2021 22:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233497AbhCJWNY (ORCPT ); Wed, 10 Mar 2021 17:13:24 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:60958 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbhCJWNF (ORCPT ); Wed, 10 Mar 2021 17:13:05 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lK74h-00DtU4-9O; Wed, 10 Mar 2021 15:13:03 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=fess.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1lK74f-001ESM-Lp; Wed, 10 Mar 2021 15:13:02 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Oleg Nesterov Cc: qianli zhao , christian@brauner.io, axboe@kernel.dk, Thomas Gleixner , Peter Collingbourne , linux-kernel@vger.kernel.org, Qianli Zhao References: <1615296712-175334-1-git-send-email-zhaoqianligood@gmail.com> <20210309182657.GA1408@redhat.com> <20210310173236.GB8973@redhat.com> Date: Wed, 10 Mar 2021 16:13:06 -0600 In-Reply-To: <20210310173236.GB8973@redhat.com> (Oleg Nesterov's message of "Wed, 10 Mar 2021 18:32:37 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1lK74f-001ESM-Lp;;;mid=;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19JTdV5RIzKGymacZ8wCcU3mj4/k7hHExw= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] exit: trigger panic when init process is set to SIGNAL_GROUP_EXIT X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Oleg Nesterov writes: > On 03/10, Eric W. Biederman wrote: >> >> /* If global init has exited, >> * panic immediately to get a useable coredump. >> */ >> if (unlikely(is_global_init(tsk) && >> (thread_group_empty(tsk) || >> (tsk->signal->flags & SIGNAL_GROUP_EXIT)))) { >> panic("Attempted to kill init! exitcode=0x%08x\n", >> tsk->signal->group_exit_code ?: (int)code); >> } >> >> The thread_group_empty test is needed to handle single threaded >> inits. > > But we can't rely on thread_group_empty(). Just suppose that the main > thread exit first, then the 2nd (last) thread exits too. It took me a minute. I think you are pointing out that there is a case where we do not set SIGNAL_GROUP_EXIT and that init actually exits. The case where all of the threads do pthread_exit() aka do_exit(). I think that implies that to have a comprehensive test would need to do: group_dead = atomic_dec_and_test(&tsk->signal->live); /* If global init has exited, * panic immediately to get a useable coredump. */ if (unlikely(is_global_init(tsk) && (group_dead || thread_group_empty(tsk) || (tsk->signal->flags & SIGNAL_GROUP_EXIT)))) { panic("Attempted to kill init! exitcode=0x%08x\n", tsk->signal->group_exit_code ?: (int)code); } Leaving the test where it is. Yes. I think that should work. Eric