Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp734197rdb; Tue, 23 Jan 2024 13:17:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGiX8ySyHcTG5eOqbLqgm5d5/uzv6me5hXutYnjECsAupyVP1BcsCgpPVSEDjuzIro5549o X-Received: by 2002:a17:906:899:b0:a2c:2437:101c with SMTP id n25-20020a170906089900b00a2c2437101cmr257424eje.13.1706044630943; Tue, 23 Jan 2024 13:17:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706044630; cv=pass; d=google.com; s=arc-20160816; b=VvXIxeWqBPWKA2ypF+TsfqNeo875R3dlKG35oD81BrC9JCGBSWGuiqHsENmcaVAunQ JE01P35+5/kLDt0UQNYt3FwqjS9WDE43FQdRaQtY6H5wM/Ppb7P8Hb4TyLBPwFsh/dRX kb/DVinRpnQNnTVrNQHoU8hAI9bs84Zv0N0hnsXI+Mm/cGIudaKmWr+oQ5bbgJcr5woC DQNtO5UJmMBvywTDE4dg0t9VKW0xJ7LO2mvIDVv/07V6NcgrkuOOCuJ5zIDsbO24rlq9 0EuR7UFse2psQ68YXK8svkO3XrDG1BHvTPjHN3bH6nZhISfK4wUp49mBuDyeC7TdQMRz Cxjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature:dkim-signature; bh=3s+NYKmSwd36BsjF0J4/1gUDj3DMNYT/x588dQ9rC4Y=; fh=uFeBTMY4UXsGZkRLeyyopYisjwj7y4onLdt27Vd+Y94=; b=jjSdby829JiHw0IPI/dupGK/xnmYnt6aUS5DzTZVdd8qx/y8MAR/WzOs4Pcwrz9Cpg IX0Dk31h9ZzP+/72SYumB5ys5pdScUp+uY8+1O+1IYPyRD6DyfekgwIGngRvoNbXfTRy zm4Ag7RfkJ/r5VzHbVdw4KGlg3RxxpaSV6nDj3veuXkdaUPDVaRqIvn2FzI0ZKe30OQf NDqrsxGFg2dmApOxBWgQv9XHdeFT656j2OtWYbjlrczX+ac7/raAev6N5GdlIPae0EbT /TEwAFtZRnfPq4s3dyB4P9nibVerVWX7RVGDQF0HuWD9GRX51cR1MHjRdo47w5dJV2q0 WgJg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=sEpcPcLh; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=cUq4dazu; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-36061-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36061-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w13-20020a17090633cd00b00a2bb419f8c4si11769768eja.974.2024.01.23.13.17.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 13:17:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36061-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=sEpcPcLh; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=cUq4dazu; arc=pass (i=1 spf=pass spfdomain=tycho.pizza dkim=pass dkdomain=tycho.pizza dkim=pass dkdomain=messagingengine.com); spf=pass (google.com: domain of linux-kernel+bounces-36061-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36061-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 1C0931F2CEEF for ; Tue, 23 Jan 2024 21:10:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDABF2C1AE; Tue, 23 Jan 2024 21:10:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b="sEpcPcLh"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cUq4dazu" Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (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 6F91729434; Tue, 23 Jan 2024 21:10:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=66.111.4.26 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706044228; cv=none; b=ufqiJkhBNBvr7w57j/bAUoC5WceiXxPDt8wRJF+xm/S07YDf+HQ9oPr9M85Re6vYkNagHIMOteCKK42PuDEHLjbmyoSiEyxbrZ7lZ7pv3O2yLCXkG8GvXI1OO5ON3MnS67Dff6w5i8dry9wjlLwZUUS/5+B9trIvKOHH5/74/oE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706044228; c=relaxed/simple; bh=dYvXX13fIYIhM9hpmdKZ+G8LhU/8/Fw9vf+MJ02McGo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=m/z/DWqFpvV64BumnRtulinw6+glSotT1ERgbxa1EGdiEZJhsg2CIrzZf1gsm0uWLcxvo2oUdWyvnaIS5CgtYb1nquSUYRVLqcFmmmbmMQwTGvPT/DMNC7KO9XqSgojGSckW+FGfXOE3QOTPYj/bb/IEFTPFlvUH/gMh7BoXcAk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza; spf=pass smtp.mailfrom=tycho.pizza; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b=sEpcPcLh; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cUq4dazu; arc=none smtp.client-ip=66.111.4.26 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tycho.pizza Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tycho.pizza Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 73F975C0191; Tue, 23 Jan 2024 16:10:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Tue, 23 Jan 2024 16:10:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tycho.pizza; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1706044225; x=1706130625; bh=3s+NYKmSwd 36BsjF0J4/1gUDj3DMNYT/x588dQ9rC4Y=; b=sEpcPcLhtFfPpPOkJfDXMOfwIa a0qNyRNYbATGRyIQ7k3r9aKBzWt5RMniCyN2/88XOqgz38bd+JNvTYuhbpqoF6t3 ALkeUYA2upmkeqA+A/t8bVwwFEGzS6nDiefBdWftpxR6umOiNy3qvx6cS8btaYlt XAS+fO0TtOmyW8Wz3bcHwxBNlGjT9ej/R15jPGuvIMQrkApDvDMs6VzSAZCkHr8d ohNHoLf4akahRm9aPNz9JNLtVql+TQAGsnpYEdhD8Fp9axuOc/rIb6sFc3+f7Ezi wMRoW3U5fLyBuehSsTDi4/qUseXBPAfDC0iY1cRc47cM4JPrQnRrQC4GmtFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1706044225; x=1706130625; bh=3s+NYKmSwd36BsjF0J4/1gUDj3DM NYT/x588dQ9rC4Y=; b=cUq4dazu13nOLFBr9VvPcgQMODY1DgLrZkR84WT1RVnJ TaxMO4CHhfyxyRfAHnvGHNf+uv2BPabdlxoIRczOGnjaXzDGUGOqTFcD1US7r7up qb9dA2akbZxdNTS1y15EqaM4F5uD1HOlOMiQQzI3jE5g2h7FhenTyRHbcJ1Neabf MFX77X7uK/dF5ZIw1tRlOot2TL4OlChAdiO1uHV+xJzdadD5iojN4kc0kiTjnSmJ oOJTyrlP3ocYbQcLonZPsG4xvxaw83XqNyQrecdmcvelAehyFGUEBlQlIV4LDtSG 44kcBiZAdI2bqLg3VXmWMHeAkeM+W6Qh6PaLZglDFQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdekkedgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvhigt hhhoucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpihiiiigrqeenucggtf frrghtthgvrhhnpeeutedttefgjeefffehffffkeejueevieefudelgeejuddtfeffteek lefhleelteenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehthigthhhosehthigthhhordhpihiiiigr X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 23 Jan 2024 16:10:21 -0500 (EST) Date: Tue, 23 Jan 2024 14:10:15 -0700 From: Tycho Andersen To: Oleg Nesterov Cc: Christian Brauner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen Subject: Re: [PATCH v3 1/3] pidfd: allow pidfd_open() on non-thread-group leaders Message-ID: References: <20240123153452.170866-1-tycho@tycho.pizza> <20240123153452.170866-2-tycho@tycho.pizza> <20240123195608.GB9978@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@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: <20240123195608.GB9978@redhat.com> On Tue, Jan 23, 2024 at 08:56:08PM +0100, Oleg Nesterov wrote: > Too late for me, but I don't understand this patch after a quick glance. > perhaps I missed something... Thanks for taking a look. > On 01/23, Tycho Andersen wrote: > > > > @@ -256,6 +256,17 @@ void release_task(struct task_struct *p) > > write_lock_irq(&tasklist_lock); > > ptrace_release_task(p); > > thread_pid = get_pid(p->thread_pid); > > + > > + /* > > + * If we're not the leader, notify any waiters on our pidfds. Note that > > + * we don't want to notify the leader until /everyone/ in the thread > > + * group is dead, viz. the condition below. > > + * > > + * We have to do this here, since __exit_signal() will > > + * __unhash_processes(), and break do_notify_pidfd()'s lookup. > > + */ > > + if (!thread_group_leader(p)) > > + do_notify_pidfd(p); > > This doesn't look consistent. > > If the task is a group leader do_notify_pidfd() is called by exit_notify() > when it becomes a zombie (if no other threads), before it is reaped by its > parent (unless autoreap). There is another path, also in release_task(), that I was trying to mirror since it deals explicitly with sub-threads but, > If it is a sub-thread, it is called by release_task() above. Note that a > sub-thread can become a zombie too if it is traced. I didn't know about this. > > __exit_signal(p); > > and, do_notify_pidfd() is called before __exit_signal() which does > __unhash_process() -> detach_pid(PIDTYPE_PID). > > Doesn't this mean that pidfd_poll() can hang? thread_group_exited() > won't return true after do_notify_pidfd() above, not to mention that > thread_group_empty() is not possible if !thread_group_leader(). I was wondering about this too, but the test_non_tgl_poll_exit test in the next patch tests exactly this and works as expected. > So. When do we want to do do_notify_pidfd() ? Whe the task (leader or not) > becomes a zombie (passes exit_notify) or when it is reaped by release_task? It seems like we'd want it when exit_notify() is called in principle, since that's when the pid actually dies. When it is reaped is "mostly unrelated". Something like, 1. in the "normal" exit_notify() paths via do_notify_parent() 2. if none of those cases are true (aka the final else in exit_notify()) and the thread is not ptraced 3. via release_task() finally if this was the thread group leader and it died before some sub-thread then in pidfd_poll(), we can do: if (!tsk || (tsk->exit_state >= 0) || thread_group_exited()) do_notify_pidfd(); ? > Either way pidfd_poll() needs more changes with this patch and it can't > use thread_group_exited(). If do_notify_pidfd() is called by release_task() > after __exit_signal(), it can just check pid_has_task(PIDTYPE_PID). I suppose this is why my test works, since pid_task(PIDTYPE_PID) is null after release_task(). But if we want it to happen earlier, we'll have to do something like the above. Tycho