Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2573913rdb; Fri, 8 Dec 2023 12:04:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUo2WJSlRt5FtH1otFbt6HSeN+A6bp103FtNEXQggLC73wnzoWHzLVTiGDUhCfeuLtR5+N X-Received: by 2002:a05:6a20:ba7:b0:18b:5a66:3f70 with SMTP id i39-20020a056a200ba700b0018b5a663f70mr560943pzh.2.1702065874866; Fri, 08 Dec 2023 12:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702065874; cv=none; d=google.com; s=arc-20160816; b=t7ggvy2+3nOAsJhem44PAEr0VmqTMBL6/ql0R0AsjOLKMwIjF5kpDXdZ1WfqLK7BXo w9hgiYnzrHaZwZ77a377SFCPQTyFHzosUGJa1J5tiGtSrMWAozIc3GXR82bPL6V75QOa bX1KZrCCobWuOaGetcQVi86AHf2CPIdiSmqg/o4rIMzThwEqJrmecogiZsykw3Sf/3I+ 976O0Os1VwWIXX5CuBtE3Dr5vzBtpfRRGuN4qldfevmUYKjzy7QK1H2sYn6DEQ7HeMPn RUPK2D18QXsr4YOWDXAmdjWLYUqAWXW3LRWD+2CmIx7aoch2fNO0tZzR5+EP2/Ir2xPZ 6KAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=GGNlAi0M3/WjzMXprO8Id6miZfyxGyNcpliBuJNnlBU=; fh=IYWfTx6MdtDYAD0oKFI/Q1p4tCJThP78XYkAVzIKibA=; b=r/L0RFqEcmBDXpismsmW+EW1/nhswH5fFgOX0VOCUmn4a2DT/jwyH0heNn3rtSwB+g UYOtMioRAKw/Pv+H6oI3sQMxYjv2h3vx5I8Gy7E0DYmPghQQHzv15NIEOUrnz8PuUhDI WMFMsXPKw47k+OUsL+TVb+FVi9d3wGyjOzTjwF/72G7SAwgAl/lxMNUGYJGLu2hzwkao MemENIP0nzsTyfpOUELYi0m9pwz0PBw9J3zNf5PL7IAzMThsg08LqFV/AJyr1tz4MrIq Kbe9/3HRuIo+WoBVr24c+C8Im1eWOYsRH82iGT4iM4QR5fS0vi+lZs6UjRXhcLip7u3s Bf9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=Z4fson34; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="cB4y2/PS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id bv127-20020a632e85000000b005c671034477si1920563pgb.539.2023.12.08.12.04.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 12:04:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@tycho.pizza header.s=fm3 header.b=Z4fson34; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b="cB4y2/PS"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B1F498076D2B; Fri, 8 Dec 2023 12:04:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbjLHUEN (ORCPT + 99 others); Fri, 8 Dec 2023 15:04:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjLHUEM (ORCPT ); Fri, 8 Dec 2023 15:04:12 -0500 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D1E711D; Fri, 8 Dec 2023 12:04:18 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 72A563200A64; Fri, 8 Dec 2023 15:04:16 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Fri, 08 Dec 2023 15:04:17 -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:sender :subject:subject:to:to; s=fm3; t=1702065855; x=1702152255; bh=GG NlAi0M3/WjzMXprO8Id6miZfyxGyNcpliBuJNnlBU=; b=Z4fson34NdZM6IcEu2 iLoZagOg8lFOwUsGY7/MgxiA3LedN4e9kJA3GykFrrqKaqcQkaCw60ioeQdo5tUd HsdIeempYYhyj0pQcCye3E+fdHu3WaEkPkjZSkxP5Y9l7UYdMwHxtF+o0aPUuGzA mVqloC3lOtZUWGKLrmRkVyontchKqZFpNRxkgwT6iofNh3Rk3hYkEzp2JvQWqGG/ fixNjBLSn7VZS4dvDpVxcoDSR7lskB75R+oOH9R1ZNW5HHvIp7qR+k2db6sj+IXi tHpMVAAKFuoLZW+IbRQ7h51HhzJB3hDdE18+dWI4IRKeaSdhu752YbLgrYkYaktg LHug== 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:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1702065855; x=1702152255; bh=GGNlAi0M3/Wjz MXprO8Id6miZfyxGyNcpliBuJNnlBU=; b=cB4y2/PSRxjPLQFaqkfAMWDth0DBB 3g62xpt6oL50ixWkQs8C0eBT7KLpMYa+9l86QazfOOhEMi9IM2i7tmV2qgAM4bzP jwCW0aSSR5QpzalgCb0thW3FgBHfZzSn0CvrS2lzLo1jOkv5U0feKE6hzvbEPoRg sOd920U+mOGYBDn+YB/9XQnb2M1w8j+zEuwIg+x002Mp5FbeR+RnBMVk/vrUP1Ut fn3wxy0VvHmuF0hecFJ35dnTfMgH4DLgrR9VCE/KKlG+EWN44kGbRn+tQM2QF2ue KhmgFnOzSpwSSv3GU8MXjiY/HKu9Z4AqWLcHRFf9HXprupx1rbfW8QoAw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudekiedgudefgecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpefvhigt hhhoucetnhguvghrshgvnhcuoehthigthhhosehthigthhhordhpihiiiigrqeenucggtf frrghtthgvrhhnpeelveduteeghfehkeeukefhudfftefhheetfedthfevgfetleevvddu veetueefheenucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuih iivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthihtghhohesthihtghhohdrphhi iiiirg X-ME-Proxy: Feedback-ID: i21f147d5:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 8 Dec 2023 15:04:13 -0500 (EST) Date: Fri, 8 Dec 2023 13:04:11 -0700 From: Tycho Andersen To: Christian Brauner Cc: Oleg Nesterov , "Eric W . Biederman" , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Tycho Andersen , Jan Kara , linux-fsdevel@vger.kernel.org, Joel Fernandes Subject: Re: [RFC 1/3] pidfd: allow pidfd_open() on non-thread-group leaders Message-ID: References: <20231130163946.277502-1-tycho@tycho.pizza> <20231130173938.GA21808@redhat.com> <20231207-weither-autopilot-8daee206e6c5@brauner> <20231207-avancieren-unbezahlbar-9258f45ec3ec@brauner> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231207-avancieren-unbezahlbar-9258f45ec3ec@brauner> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 08 Dec 2023 12:04:32 -0800 (PST) On Thu, Dec 07, 2023 at 10:25:09PM +0100, Christian Brauner wrote: > > If these concerns are correct > > So, ok. I misremebered this. The scenario I had been thinking of is > basically the following. > > We have a thread-group with thread-group leader 1234 and a thread with > 4567 in that thread-group. Assume current thread-group leader is tsk1 > and the non-thread-group leader is tsk2. tsk1 uses struct pid *tg_pid > and tsk2 uses struct pid *t_pid. The struct pids look like this after > creation of both thread-group leader tsk1 and thread tsk2: > > TGID 1234 TID 4567 > tg_pid[PIDTYPE_PID] = tsk1 t_pid[PIDTYPE_PID] = tsk2 > tg_pid[PIDTYPE_TGID] = tsk1 t_pid[PIDTYPE_TGID] = NULL > > IOW, tsk2's struct pid has never been used as a thread-group leader and > thus PIDTYPE_TGID is NULL. Now assume someone does create pidfds for > tsk1 and for tsk2: > > tg_pidfd = pidfd_open(tsk1) t_pidfd = pidfd_open(tsk2) > -> tg_pidfd->private_data = tg_pid -> t_pidfd->private_data = t_pid > > So we stash away struct pid *tg_pid for a pidfd_open() on tsk1 and we > stash away struct pid *t_pid for a pidfd_open() on tsk2. > > If we wait on that task via P_PIDFD we get: > > /* waiting through pidfd */ > waitid(P_PIDFD, tg_pidfd) waitid(P_PIDFD, t_pidfd) > tg_pid[PIDTYPE_TGID] == tsk1 t_pid[PIDTYPE_TGID] == NULL > => succeeds => fails > > Because struct pid *tg_pid is used a thread-group leader struct pid we > can wait on that tsk1. But we can't via the non-thread-group leader > pidfd because the struct pid *t_pid has never been used as a > thread-group leader. > > Now assume, t_pid exec's and the struct pids are transfered. IIRC, we > get: > > tg_pid[PIDTYPE_PID] = tsk2 t_pid[PIDTYPE_PID] = tsk1 > tg_pid[PIDTYPE_TGID] = tsk2 t_pid[PIDTYPE_TGID] = NULL > > If we wait on that task via P_PIDFD we get: > > /* waiting through pidfd */ > waitid(P_PIDFD, tg_pidfd) waitid(P_PIDFD, t_pid) > tg_pid[PIDTYPE_TGID] == tsk2 t_pid[PIDTYPE_TGID] == NULL > => succeeds => fails > > Which is what we want. So effectively this should all work and I > misremembered the struct pid linkage. So afaict we don't even have a > problem here which is great. It sounds like we need some tests for waitpid() directly though, to ensure the semantics stay stable. I can add those and send a v3, assuming the location of do_notify_pidfd() looks ok to you in v2: https://lore.kernel.org/all/20231207170946.130823-1-tycho@tycho.pizza/ Tycho