Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2962496yba; Sat, 18 May 2019 06:42:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzON9m0dwEIP8yg+iDUKVRV9nvuTwRCh907CAxQ3noepe9qbVJcOgY13rjTWMGU5u67TLx8 X-Received: by 2002:a63:d949:: with SMTP id e9mr62711003pgj.437.1558186934077; Sat, 18 May 2019 06:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558186934; cv=none; d=google.com; s=arc-20160816; b=QdcuHcW98jOhOd88p2JM7Z/lCmcyQL8NWMUJodA7LuUJWhRDcyFSwrBw6H6HfLl7n3 Tht1vnvCG07/7E7Jmu0Y+5bf1QaUB9OLknZjyXLJaa4ebX5g0NQfDWyn/PMYiHuGjaFO etm49wEvXCSDy8CY+LDwEP9nYkxWSLN/u8A9o6rxPfbvVXLDfJ5Bjtgqi4CVZjl6tmqT RLWZosQ09cJvmYVvx/dRK0fopctIBDrJQ1WTb1O9Dt5/CPj1PK20DGYIdK5Md7DUC0GB Olq9Sgl4xT5oR6sjDLZRpWNbi23TjiqqJLhO4mBYdTpBJ2YyTc5SqI7e0BOmy/MQM8JL O8wg== 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=kuxvODYNXQX1UADGYTekrXKJHl9GqTdixhHyMJoLFkg=; b=bvxOINcFYdTbr0P+Gctw2nW8hXiPkC64EP+chzkN7rVuwGJvaBR+TpriuZMli68qO6 O7klxJIjNNJgxn699YltHH72nPLPgnjbpSE3pv4LOhyQMBYJNlpPOsYjKKl0/IDAbIaD ZwbU2xEvNaqGnOLUtn5NuGlE/BN2tBHmd5Oh4A6jr1kCk1Fl+GpN436Xxj2XKWxaQJKx 70rRbuUjTmJxCtJBB7k1HcpCz7mFQi5DH8RgPDrL3T1VZru4UN5CoAW4SpuXUcwMlLvr htTT/K1AohREeCG84ifGcjKH1HDtjlcAjxzXGqC6N6eq+8buh+fvsLSJVLhYMiaPPDln UU+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brauner.io header.s=google header.b=MzXf8JwF; 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 s17si11311768pgj.186.2019.05.18.06.41.28; Sat, 18 May 2019 06:42:14 -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=MzXf8JwF; 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 S1729798AbfERKFK (ORCPT + 99 others); Sat, 18 May 2019 06:05:10 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:47090 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729301AbfERKFI (ORCPT ); Sat, 18 May 2019 06:05:08 -0400 Received: by mail-ed1-f68.google.com with SMTP id f37so14639367edb.13 for ; Sat, 18 May 2019 03:05:06 -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=kuxvODYNXQX1UADGYTekrXKJHl9GqTdixhHyMJoLFkg=; b=MzXf8JwF72gJj2Pq8n12P+UywZxc2BVXTvpiVUKrEniJVb1LIFP3IbcOliQYISdvq7 CigvtYVzwi+8s8BzhGA7JzeYEAEgELRKSJUGXkBeKo3jIoY+k+AIz1NIGNQ3IbqWFvd/ pZcoiBfjP1G87UNeXXgpYPrDlzF+SvvAxTS1B9J01RvJsEbVREubCnWtrpwlE+W8uhC8 abJb2p1WNSljrqCFAQH7at9A4yXrlhg+5ZrhECybT+pFDJTv4XLPhvmKoEIQriQEdsEE 2qeWRYeIhjWVjN8Omnws0ZotrB2BKKuxhO4+QGekj7Ec6VajrUKLl5oRB10tcR/KFGxb SomA== 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=kuxvODYNXQX1UADGYTekrXKJHl9GqTdixhHyMJoLFkg=; b=N/RSNISHPl/2Y54+QeSOKnW8w4nbXFFqybLcvb/acWoy25ixUHAAlTFlgjTbhHOSv2 8OqIwsivVO3oss/wnhcNJ+CINmlNKkgSG1Y2fEPznBzqI4YV4fy4Deg62NGwme2GHM7k LFHePnLPi5cAWyRtKpFzoaKPMrOSI6JqRee7Ht/0zWSj3IXmHeJvVHGDDutPt+FsIjuP G5gUTVdWRKqiRhpYrkfrBf1TbtpnclD8mTYre+BUAJjT8pVHUSZvFaDqjstNICe5GDxL pfh1t3Epumi9uChpsn7xxH58DellauVdHYXtgDfNSdP2U6yuByHQdszawi+sUIkcob8m MXdA== X-Gm-Message-State: APjAAAUV2fLFhNc7Lp18QZZGBX20On2cr30XUNW+yZmyrcT9PdTRwdl9 2cKOtrf2I8Ao4ndpJVJQBuRfoA== X-Received: by 2002:a50:b82d:: with SMTP id j42mr63022736ede.186.1558173905455; Sat, 18 May 2019 03:05:05 -0700 (PDT) Received: from brauner.io ([46.183.103.8]) by smtp.gmail.com with ESMTPSA id y30sm3741910edc.83.2019.05.18.03.04.59 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 18 May 2019 03:05:04 -0700 (PDT) Date: Sat, 18 May 2019 12:04:46 +0200 From: Christian Brauner To: Joel Fernandes Cc: jannh@google.com, oleg@redhat.com, viro@zeniv.linux.org.uk, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, arnd@arndb.de, akpm@linux-foundation.org, cyphar@cyphar.com, dhowells@redhat.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.orgg, 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, dancol@google.com, serge@hallyn.com, surenb@google.com, Geert Uytterhoeven , kernel-team@android.com Subject: Re: [PATCH v1 1/2] pid: add pidfd_open() Message-ID: <20190518100435.c5bqpcnra53dsr6p@brauner.io> References: <20190516135944.7205-1-christian@brauner.io> <20190516224949.GA15401@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190516224949.GA15401@localhost> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 18, 2019 at 05:48:03AM -0400, Joel Fernandes wrote: > Hi Christian, > > For next revision, could you also CC surenb@google.com as well? He is also > working on the low memory killer. And also suggest CC to > kernel-team@android.com. And mentioned some comments below, thanks. Yip, totally. Just added them both to my Cc list. :) (I saw you added Suren manually. I added the Android kernel team now too.) > > On Thu, May 16, 2019 at 03:59:42PM +0200, Christian Brauner wrote: > [snip] > > diff --git a/kernel/pid.c b/kernel/pid.c > > index 20881598bdfa..4afca3d6dcb8 100644 > > --- a/kernel/pid.c > > +++ b/kernel/pid.c > > @@ -38,6 +38,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -451,6 +452,55 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) > > return idr_get_next(&ns->idr, &nr); > > } > > > > +/** > > + * pidfd_open() - Open new pid file descriptor. > > + * > > + * @pid: pid for which to retrieve a pidfd > > + * @flags: flags to pass > > + * > > + * This creates a new pid file descriptor with the O_CLOEXEC flag set for > > + * the process identified by @pid. Currently, the process identified by > > + * @pid must be a thread-group leader. This restriction currently exists > > + * for all aspects of pidfds including pidfd creation (CLONE_PIDFD cannot > > + * be used with CLONE_THREAD) and pidfd polling (only supports thread group > > + * leaders). > > + * > > + * Return: On success, a cloexec pidfd is returned. > > + * On error, a negative errno number will be returned. > > + */ > > +SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags) > > +{ > > + int fd, ret; > > + struct pid *p; > > + struct task_struct *tsk; > > + > > + if (flags) > > + return -EINVAL; > > + > > + if (pid <= 0) > > + return -EINVAL; > > + > > + p = find_get_pid(pid); > > + if (!p) > > + return -ESRCH; > > + > > + ret = 0; > > + rcu_read_lock(); > > + /* > > + * If this returns non-NULL the pid was used as a thread-group > > + * leader. Note, we race with exec here: If it changes the > > + * thread-group leader we might return the old leader. > > + */ > > + tsk = pid_task(p, PIDTYPE_TGID); > > Just trying to understand the comment here. The issue is that we might either > return the new leader, or the old leader depending on the overlap with > concurrent de_thread right? In either case, we don't care though. > > I suggest to remove the "Note..." part of the comment since it doesn't seem the > race is relevant here unless we are doing something else with tsk in the > function, but if you want to keep it that's also fine. Comment text should > probably should be 'return the new leader' though. Nah, I actually removed the comment already independently (cf. see [1]). [1]: https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=pidfd_open&id=dcfc98c2d957bf3ac14b06414cb2cf4c673fc297 > > > + if (!tsk) > > + ret = -ESRCH; > > Perhaps -EINVAL? AFAICS, this can only happen if a CLONE_THREAD pid was > passed as argument to pidfd_open which is invalid. But let me know what you > had in mind.. Hm, from the kernel's perspective ESRCH is correct but I guess EINVAL is nicer for userspace. So I don't have objections to using EINVAL. My first version did too I think. Thanks! Christian