Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp321425rdb; Sat, 27 Jan 2024 07:56:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfJOFyJplesXj+SrgutrY7RSz2zpc1I90EvHr4QV2DHUmvgFb9CEqiWYat0iMt0CbHylgg X-Received: by 2002:adf:dd82:0:b0:33a:e703:ff37 with SMTP id x2-20020adfdd82000000b0033ae703ff37mr293453wrl.122.1706370963445; Sat, 27 Jan 2024 07:56:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706370963; cv=pass; d=google.com; s=arc-20160816; b=LVJEiWdwHeVQKnSfxYE9T7o7p2ewi0Dz5JrX+R043s5DCMxsuoS0Z1zPbOhB4pDZzv tlS1pkamt5cCGlOLciS/LJP12GOmG+JcxWKlkvwn8B4HPVU1IpYBYU8UImFswdWGSub1 b3vEMaIQ/dSuoai+T5M9nqQA6+1R7U7n5rfmN5SWXYhAw/2UbUIqDlT5j97oJy6r1rXw GIlXSMnX4ap2PFUkJwvpom6yULaAzjB2Z/Q50WoeiTtrLvTuXtUIBy8aaXKKNu8p3EpX ngWLVIzggUy4ebYpvL71HgizKSz9iVEn+Q6Np0hXN8pTSzrASg5CT5+3HwMFfVTE63Bj /LsA== 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=XfDO2zRIy9wsN7s/nMkXYnVjBmeZXSXaD7ior0H/odU=; fh=+pQQVWC6LKwXuTBmhlwvzqB5oDujtV1dR/Djy78dDYY=; b=WPrLrVIrDJoMKenzvq8E1Ht+082W3Fkny70GdbcUb3qm19gXtKAn2OL4fEkPxDWiZY ZX9QOBoosmJK/PPDln7zg44M2Wq9scuavQCWFiCxRPDFhrhS1avZGzEzEXhNyooni1sB kKnjoNFcmJpk5FQxl2n+Ckgi/+ehQiNG01DOmeyNlpUDqj2az3c69BQdc5PorYduGpJZ 5QdWnF0bSk5FOUUNeCCuytT5VWRLyuVUiYOtwmaVYWPuJiqQ3EMO/iJyrgXlWJoIIwGF yCD0KJs+gvHXIqjJxFXhAoOJy5i5biL/Nx1ub/Bns29hJwnkO3GMlk3XzfiT17y4XN5o 6c4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=lVxB7mZj; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f7pxCGsB; 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-41259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41259-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o1-20020a056402444100b0055df299dad5si1062068edb.376.2024.01.27.07.56.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 07:56:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm2 header.b=lVxB7mZj; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=f7pxCGsB; 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-41259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41259-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 D68091F22A13 for ; Sat, 27 Jan 2024 15:56:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DEFB29425; Sat, 27 Jan 2024 15:55:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tycho.pizza header.i=@tycho.pizza header.b="lVxB7mZj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="f7pxCGsB" Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (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 110051DFCF; Sat, 27 Jan 2024 15:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706370952; cv=none; b=pN0VUjvaHLlLQ3ckf3S19lQ0QxjMOIReiENjPOfKai6nUDYkYdzJld4c2dvKvHM8avR82vCwwmqkqc0umM+qO5n8RXYTPNvEPC6gwG54nNLP2FnS10BBjWC/iIm/tIZBqTAaklOOf1bviz1xhvT4Rhi2tji4F9PgC2Yk49pnziY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706370952; c=relaxed/simple; bh=6pSCSML+JZghD5BCwhywGlyJjYkC36czSX7oYgXB6kI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QwLTvQIFjFp7yoHKg4G6fSe+eZk7pHHVgHTgaVAGgfK9kqRXEZd/BSWmU68R3rkwBsbskh698bb4FGY/8PDUaJOb0bgSIwMldXuRhnwgZDH7uphCd2V0WgJR2Z0OnfInh0VEes/mvgipeqqoCR4SeSMN4sVacWK8jaIJZnRfO/s= 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=lVxB7mZj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=f7pxCGsB; arc=none smtp.client-ip=103.168.172.144 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 mailfout.nyi.internal (Postfix) with ESMTP id E1D4D138005D; Sat, 27 Jan 2024 10:55:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Sat, 27 Jan 2024 10:55:48 -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=1706370948; x=1706457348; bh=XfDO2zRIy9 wsN7s/nMkXYnVjBmeZXSXaD7ior0H/odU=; b=lVxB7mZjA6tJNRWp3txpcXiHnh FHpbqi1YB7ihEvndA27XeZudZmGvQT20qo0cfSfV2PDGYRPrcONjySGDwg+NRLAe HH161jTvi1GZgm8i6bLcCAs0TajaGLgiqqloJWpOVhOCJzTE141AB8S5dV945wTx RFbO7m5m5T4cCXE8R1Hnb2F7H8ELpOH/jflbqVj/JtEmCFu5REuVfqa52bwGXGFZ DLWf4yPFNTcOmmlhfEnoYssQoNVmzJSy86Ws9n5++kCUNyqG4XEfZ0av4hM8vWFR mSCdFgch1ABMs5Eb5CtumWzXgNL47YazthIZVPFybEvDK5ZtjjHdLVJr4eZA== 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=1706370948; x=1706457348; bh=XfDO2zRIy9wsN7s/nMkXYnVjBmeZ XSXaD7ior0H/odU=; b=f7pxCGsBi50yamg5NRNINORKpelSWzECMMUqPIyC6J6E f2kOTL/u+dXKhVz6PEPARiVw6Tp0f2jUSrQvCSCFfkdUcp8IS33SQG/zSbv7NOQu i+x43Gh4ZQuduk+2nI0QY1q9PqL1pWrlvKA9e+dnXVzkIrFl2DRaIW6hwrEI/HA+ PrOW8FUbjgeAjl9HhJjJhjU4Jt2InI85mCHeSSLH+m6JwF2eDHM4ROgCDd/UYPMJ hbOcV2CpnFT/x0pWl2ZCcDMjCGdedTeyFumQw4v/7fj8BDxZ8rHNzgmqT0m9rTI+ GCEdAfYKxWhkZ5e06iQw90igFl8K8w6gm5V+G0mw+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdelledgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepvfihtghh ohcutehnuggvrhhsvghnuceothihtghhohesthihtghhohdrphhiiiiirgeqnecuggftrf grthhtvghrnhepueettdetgfejfeffheffffekjeeuveeifeduleegjedutdefffetkeel hfelleetnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh epthihtghhohesthihtghhohdrphhiiiiirg X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 27 Jan 2024 10:55:47 -0500 (EST) Date: Sat, 27 Jan 2024 08:55:46 -0700 From: Tycho Andersen To: Oleg Nesterov Cc: Christian Brauner , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen , "Eric W. Biederman" 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> <20240125140830.GA5513@redhat.com> <20240127105410.GA13787@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: <20240127105410.GA13787@redhat.com> On Sat, Jan 27, 2024 at 11:54:32AM +0100, Oleg Nesterov wrote: > Hi Tycho, > > On 01/26, Tycho Andersen wrote: > > > > On Thu, Jan 25, 2024 at 03:08:31PM +0100, Oleg Nesterov wrote: > > > What do you think? > > > > Thank you, it passes all my tests. > > Great, thanks! > > OK, I'll make v2 on top of the recent > "pidfd: cleanup the usage of __pidfd_prepare's flags" > > but we need to finish our discussion with Christian about the > usage of O_EXCL. > > As for clone(CLONE_PIDFD | CLONE_THREAD), this is trivial but > I think this needs another discussion too, lets do this later. > > > > + /* unnecessary if do_notify_parent() was already called, > > > + we can do better */ > > > + do_notify_pidfd(tsk); > > > > "do better" here could be something like, > > > > [...snip...] > > No, no, please see below. > > For the moment, please forget about PIDFD_THREAD, lets discuss > the current behaviour. > > > but even with that, there's other calls in the tree to > > do_notify_parent() that might double notify. > > Yes, and we can't avoid this. Well, perhaps do_notify_parent() > can do something like > > if (ptrace_reparented()) > do_notify_pidfd(); > > so that only the "final" do_notify_parent() does do_notify_pidfd() > but this needs another discussion and in fact I don't think this > would be right or make much sense. Lets forget this for now. It seems like (and the current pidfd_test enforces for some cases) we want exactly one notification for a task dying. I don't understand how we guarantee this now, with all of these calls. > > This brings up another interesting behavior that I noticed while > > testing this, if you do a poll() on pidfd, followed quickly by a > > pidfd_getfd() on the same thread you just got an event on, you can > > sometimes get an EBADF from __pidfd_fget() instead of the more > > expected ESRCH higher up the stack. > > exit_notify() is called after exit_files(). pidfd_getfd() returns > ESRCH if the exiting thread completes release_task(), otherwise it > returns EBADF because ->files == NULL. This too doesn't really > depend on PIDFD_THREAD. Yup, understood. It just seems like an inconsistency we might want to fix. > > I wonder if it makes sense to abuse ->f_flags to add a PIDFD_NOTIFIED? > > Then we can refuse further pidfd syscall operations in a sane way, and > > But how? We only have "struct pid *", how can we find all files > "attached" to this pid? Yeah, we'd need some other linkage as Christian points out. But if there is a predicate we can write that says whether this task has been notified or not, it's not necessary. I just don't understand what that is. But maybe your patch will make it clearer. Tycho