Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp118721rdb; Thu, 25 Jan 2024 09:52:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOCjaY20AGhUdy0P4rsrZsV0gO5r4LKDr69mJgmIite+R6cItNyirAX4N9ap/XCv8eUa44 X-Received: by 2002:a05:620a:8396:b0:783:289c:2c4a with SMTP id pb22-20020a05620a839600b00783289c2c4amr62213qkn.128.1706205164168; Thu, 25 Jan 2024 09:52:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706205164; cv=pass; d=google.com; s=arc-20160816; b=mU2hDEci+Y5O11TAhfOJKZNzbuXtmKiBptHjdVsUxAUGL1SgvQMrYjtmMnFgbP89SM 0U9hVlRgcHv+MXuBmM31gt0/WYDPW/sRLsrlJoxxJXPGAehcDaHlU0Rgnb/WXznh4RLf tvMQxfY2bkFlF+Y3SjsRV1yPY+zz5c1W3jHxAqd+A2m2XADl0v/joQ1lN5hllakmHKlo uVU5aUTJeBY86IDinTJRzwzUCgQxADgu7RR+GzMYkOiy/hVrfd9/q1NenLKxfRnA6Kqp xxly6PbxKPmf2l2JTPzyYaKOarP+LIdOuED7+YOJpNmoD/gg9jIFVKr5T1SzShbdQNLc Qjhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=g5i6hZoO43ocf7ks9R4XVTZTyBaBFXg6GPxWhGdS98Y=; fh=ttd5M4oh2J/lSvqfHyfhVQGCXE2K4fyBxVoE/QtpyDg=; b=vyulmw0Z6KqMd9NwRpvKCNrFGBXKkS2hqJownUTMx8yVQjn+XXG6tHp+5JQPJqxlH1 rohFSn2Wir8mjDe+xwqVKcED53Z9HglHqiyPhNfd9IypGV3KGkr0/61QjQIHfdElA1J8 AvbuXyykKSR0LIoOr1bLgpMx1c98yo1Lrnw04jrFPAxjBt4hS0UmAvQVYBDUhesAuWTF zo8sBHh7TSeoYP3ARUt7PGfRyDjUEbXnHyWqxJYkJpxlHI1aYa77qcZH9nOArj0DlxT8 E1B8VGih9kjwYdofeop0c+UsmRT6oxLKY1kHHGbdW9JWIlTPpoHNWm5ehmYBjRKo2zT9 dnjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=brdktsig; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-39057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o6-20020a05620a0d4600b00783527b5f9bsi12855147qkl.605.2024.01.25.09.52.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 09:52:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=brdktsig; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-39057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39057-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E5EB81C22C3E for ; Thu, 25 Jan 2024 17:52:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5773C133421; Thu, 25 Jan 2024 17:52:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="brdktsig" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 E754413173D for ; Thu, 25 Jan 2024 17:52:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205156; cv=none; b=Esh4zWwGrAmbrkojTvPIux9dhABkY6a4bYp7l+zBtFCGoy257Y4xSLklk9AUXn7/iXdvkh5c95STDymE8uAhWAgR/AKh4audfupDCNL47wrBQNEfuRGFnE6pCtMQ9kcUl3Bqk+6F/WRLJioRBs/sjPO+F1L7f82q4UmGT96pnpA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706205156; c=relaxed/simple; bh=Yy1GT2lp77XeMuurRLrfbVb7XC2c9zvSK8wdBd9j4ik=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BT5+QO8WFDmNWOY/Xs5yjwUnWYnQzEkRKw9cezJAFA1lsxvYPQgi4vuCNqNab2KVc4ujB0eRUMJNitI3UkpDoGzpcMYc0AUiB0hDFOfDmPR08qMAcT5nx+/QuMvJoALNNmTVLG+bwoOZUK5+HDNBGABZ0KOA72plRbLQ7vbI42E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=brdktsig; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706205154; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=g5i6hZoO43ocf7ks9R4XVTZTyBaBFXg6GPxWhGdS98Y=; b=brdktsigcE+5aUnJnkMJTzj++O9/FclPytV/zh/8uRWyqW2U9D7xGRQxG0UH5vbMPCxCJF cyL07AERcnixy+puFvXGM75aT6oMN7b4yKUB/idONAVwMBy9GKuQ/BUxr+8YfRojD4DBCL 4ceQfvwy3VKvRe7heTUzfXM3c/ewDaI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-i6VYpv1nNoqo5h8Snemz_Q-1; Thu, 25 Jan 2024 12:52:30 -0500 X-MC-Unique: i6VYpv1nNoqo5h8Snemz_Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E98748489B1; Thu, 25 Jan 2024 17:52:29 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.14]) by smtp.corp.redhat.com (Postfix) with SMTP id 49EC440C106C; Thu, 25 Jan 2024 17:52:28 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Thu, 25 Jan 2024 18:51:16 +0100 (CET) Date: Thu, 25 Jan 2024 18:51:14 +0100 From: Oleg Nesterov To: Christian Brauner Cc: Tycho Andersen , 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: <20240125175113.GC5513@redhat.com> References: <20240123153452.170866-1-tycho@tycho.pizza> <20240123153452.170866-2-tycho@tycho.pizza> <20240123195608.GB9978@redhat.com> <20240125140830.GA5513@redhat.com> <20240125-tricksen-baugrube-3f78c487a23a@brauner> 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: <20240125-tricksen-baugrube-3f78c487a23a@brauner> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 On 01/25, Christian Brauner wrote: > > > > When it is reaped is "mostly unrelated". > > > > Then why pidfd_poll() can't simply check !task || task->exit_state ? > > > > Nevermind. So, currently pidfd_poll() succeeds when the leader can be > > Hm, the comment right above mentions: > > /* > * Inform pollers only when the whole thread group exits. > * If the thread group leader exits before all other threads in the > * group, then poll(2) should block, similar to the wait(2) family. > */ > > reaped, iow the whole thread group has exited. Yes, but the comment doesn't contradict with what I have said? > > But even if you are the > > parent, you can't expect that wait(WNOHANG) must succeed, the leader > > can be traced. I guess it is too late to change this behaviour. > > Hm, why is that an issue though? Well, I didn't say this is a problem. I simply do not know how/why people use pidfd_poll(). I mostly tried to explain why do I think that do_notify_pidfd() should be always called from exit_notify() path, not by release_task(), even if the task is not a leader. > Because a program would rely on WNOHANG to hang on > a ptraced leader? That seems esoteric imho. To me it would be usefule, but lets not discuss this now. The "patch" I sent doesn't change the current behaviour. > > What if we add the new PIDFD_THREAD flag? With this flag > > > > - sys_pidfd_open() doesn't require the must be a group leader > > Yes. > > > > > - pidfd_poll() succeeds when the task passes exit_notify() and > > becomes a zombie, even if it is a leader and has other threads. > > Iiuc, if an existing user creates a pidfd for a thread-group leader and > then polls that pidfd they would currently only get notified if the > thread-group is empty and the leader has exited. > > If we now start notifying when the thread-group leader exits but the > thread-group isn't empty then this would be a fairly big api change Hmm... again, this patch doesn't (shouldn't) change the current behavior. Please note "with this flag" above. If sys_pidfd_open() was called without PIDFD_THREAD, then sys_pidfd_open() still requires that the target task must be a group leader, and pidfd_poll() won't succeed until the leader exits and thread_group_empty() is true. Oleg.