Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp704248yba; Wed, 15 May 2019 08:32:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwaLnXKnGuvC6MrMFpx/vyodeoVMdWxQjLUo6T1ZSdLe7O/t0Rgvro+CrMOxCPFI7sYHLpT X-Received: by 2002:a17:902:f215:: with SMTP id gn21mr44374498plb.194.1557934342983; Wed, 15 May 2019 08:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557934342; cv=none; d=google.com; s=arc-20160816; b=GyPV4yqPP3yW0nXcPDMAdE8AjYs95DD0bkyKANuTV+MmsdRzyB8i1/1LwhDgxFmuqY nLFrOilpJB+JdwgY45ISpDNqDESvVekVexItyV5Xl3Txdzgi2V/HQ9QxCVjavZPJT5xp OjshxTND+EXkzgVeTzi88mMp4FN03gVvB+MO4SBc+OG0IZF/pems5lzYPgGPkyLryjZ+ xrwjIJrGyGXEj6UoU+s/jqMaDjtymYpnNlkTpz4YjFMaCwfabkJZu2Yx0qSj/w74vIB6 7DyKJxat2WbFzry8pDhcreaUhaeuHAx+fUbbngNCgdA/Zrf/VomsDb8zTRKPRjoDg5IY km6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aA/9xJj7LTMF1BWw8aRur3CJhiNYxnU3NsvAQ/tm1xk=; b=symDJq3OXYscE69pVt5+P9o5yUt02cxf3NetWCZnbNfoEHYnj3h+Ox8hynZTFbAR2C CYwciLXhfg8Nfde0eLoip+R5VYlh6rY8rnsWlBM+KTmyw3Rp624KoD7YQB+H6kKoTtOZ ByClHll/jS2xboHYLG5tRIl9Y34+MVf7bAXoPfGw6CPZlPHQqdPeFTdlZHyq5t4OdTHd ByXJkLAH5piNTIiflfggK0C64fkhY4w4WDCbWnzGunHufWCQlbWFUJA/nOCrn4Jh7P8j diptXkP8Fl6haXOuS4zobow2fuhPPDvRAomMPAXU3hlGRKUPaatJWOwYR79wrhEnaEXp Z//A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=cVOJomie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p66si2419522pfb.34.2019.05.15.08.32.07; Wed, 15 May 2019 08:32:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=cVOJomie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbfEOPat (ORCPT + 99 others); Wed, 15 May 2019 11:30:49 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:40607 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728404AbfEOPas (ORCPT ); Wed, 15 May 2019 11:30:48 -0400 Received: by mail-ed1-f65.google.com with SMTP id j12so393222eds.7 for ; Wed, 15 May 2019 08:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=aA/9xJj7LTMF1BWw8aRur3CJhiNYxnU3NsvAQ/tm1xk=; b=cVOJomieev/iQakiPOTryvyjScY68JwrcjZ9tnp9aeBqv3wRx4Edk6Zam5C4dpe1lU ogJ1bz/0uxayIY+dTGNRsGRKQE6a7udSOJYX/3GGdfJsVPiUlo9NIVE5wtEn+5hBwiSU gwP9J1DGbHYliH8LbuzUv/B66fmaNK+5+P4Nf0pkHXalxp2DHQe3TjDimH0gP6oUwq5l okb7EvO9DMTE9eTKyMdqlLNyrY47JfXoH49cTCN0H2L4KRmjYeMaDxi5FvoPvo3asXpV 5VjgjpZVUupeOdTmVGMkhRg4ZLi1nCgbsXBRTgk7m9FRnUbqV0616Vj7CPnf3pkdvUzD ZpUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=aA/9xJj7LTMF1BWw8aRur3CJhiNYxnU3NsvAQ/tm1xk=; b=Wal+ttjjwFldc3lUWn0MMKylccvAxjjraoBl3awhyWDQs28rM+VrI7NESK8oZT6P5H RMSMH/QBnC90OV+uks7lYh/TeT0Sj71leX2Dt9xVI0ASax4R8hmtgiV85kh7Th86PXj2 Hlib/0V1pQmjDuzClsktrw7omJhnoE/snfDhCTcLIkVw7X1KFebu1NIqeRwfJ6d+GfyL y9dmKIUQb376EZb2kKcm9xMkMaJ4e57syk8z0abDBBvjx03T1EHC8MUsI1XmENdU0beh PWo4gBo828/GXIHFMCEaZDUX7dzKwM2LkOB1i5uG1DLrwiDpmZtlvG+dXAJilCoxlXSc 2wig== X-Gm-Message-State: APjAAAWPvkW6yEiXE39y24L2S8UD1ajYVtdo4xoHP1sy8drns8BotxSZ zZbW9tdVtNTpnNxoapBC/kYWfg== X-Received: by 2002:a50:99ca:: with SMTP id n10mr44141540edb.279.1557934246270; Wed, 15 May 2019 08:30:46 -0700 (PDT) Received: from brauner.io ([193.96.224.243]) by smtp.gmail.com with ESMTPSA id d4sm924077edk.46.2019.05.15.08.30.43 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 15 May 2019 08:30:45 -0700 (PDT) Date: Wed, 15 May 2019 17:30:42 +0200 From: Christian Brauner To: Oleg Nesterov Cc: jannh@google.com, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, arnd@arndb.de, dhowells@redhat.com, akpm@linux-foundation.org, cyphar@cyphar.com, ebiederm@xmission.com, elena.reshetova@intel.com, keescook@chromium.org, luto@amacapital.net, luto@kernel.org, tglx@linutronix.de, linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 1/2] pid: add pidfd_open() Message-ID: <20190515153041.cshzaj7xhf2p4zv7@brauner.io> References: <20190515100400.3450-1-christian@brauner.io> <20190515143857.GB18892@redhat.com> <20190515144927.f2yxyi6w6lhn3xx7@brauner.io> <20190515151912.GE18892@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190515151912.GE18892@redhat.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 15, 2019 at 05:19:13PM +0200, Oleg Nesterov wrote: > On 05/15, Christian Brauner wrote: > > > > On Wed, May 15, 2019 at 04:38:58PM +0200, Oleg Nesterov wrote: > > > > > > it seems that you can do a single check > > > > > > tsk = pid_task(p, PIDTYPE_TGID); > > > if (!tsk) > > > ret = -ESRCH; > > > > > > this even looks more correct if we race with exec changing the leader. > > > > The logic here being that you can only reach the thread_group leader > > from struct pid if PIDTYPE_PID == PIDTYPE_TGID for this struct pid? > > Not exactly... it is not that PIDTYPE_PID == PIDTYPE_TGID for this pid, > struct pid has no "type" or something like this. > > The logic is that pid->tasks[PIDTYPE_XXX] is the list of task which use > this pid as "XXX" type. > > For example, clone(CLONE_THREAD) creates a pid which has a single non- > empty list, pid->tasks[PIDTYPE_PID]. This pid can't be used as TGID or > SID. > > So if pid_task(PIDTYPE_TGID) returns non-NULL we know that this pid was > used for a group-leader, see copy_process() which does Ah, this was what I was asking myself when I worked on thread-specific signal sending. This clarifies quite a lot of things! Though I wonder how one reliably gets a the PGID or SID from a PIDTYPE_PID. > > if (thread_group_leader(p)) > attach_pid(p, PIDTYPE_TGID); > > > If we race with exec which changes the leader pid_task(TGID) can return > the old leader. We do not care, but this means that we should not check > thread_group_leader(). Nice! Thank you, Oleg! :) Christian