Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp851671img; Wed, 20 Mar 2019 12:14:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJ0aiLVTYuBRvzqU33HkedIWCm77eZLw+ZtsUofFintH8DIkVzsOPsH+qhzlGOnMHHNXxQ X-Received: by 2002:a65:64d5:: with SMTP id t21mr9170730pgv.266.1553109241735; Wed, 20 Mar 2019 12:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553109241; cv=none; d=google.com; s=arc-20160816; b=A0i947tXwJwKMApZK9Sr358wYOCp7um5PONkSBIPMajeQrYUu0DduHiS+utT4ffzZ1 VFi2qts+0dHI8TWUvhMxVwO1n5LhNabeR6aNdauY8taqbWw/JL+6Xk2ojZWLhZILbtgv GahbmkJD5jVYOwAJcb3Bxc2B9X91zRaVcJzQ4MHm2ymo1B/O0QzSHnKbrJbOvaYf57KU rxStBfqV2UuqP9GGQMaLzTcBv8rXD2AnLOXatxTQJao91TpGKtTxFz7JwHimwU4/KK4H Xhchn23V3MH4bFT6owvgnE7oXpdbCoQz6lp+xR1EQwx0/UmpQZnKms8jlrN4lmG8ETqf exKA== 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=T3v6cngzSTNsn8JWqBXhJFmbZpKUUvu9y1fz3VFVogQ=; b=p1MNERGa6Q/bQj1Fy3uHqoJvaAMF03DQd+EmdSojJsdh511j0XOnxVzeRpgGOQdYwv oDuTZGqyIIWIBpa/2155O0Tkox4fMMakhFxtu/dSU21TVCtgsTCbkC23fyo5x3bUSZwl fQLv/JnQy1N4IGqGKo1m+HWo5sdSohGvAWcYkvowlvqRCKtF2RGdNOANwFDDsWSnQCgj oLJYc6mZHPbcPOmQgDuQ7IJCjU3kLEh9DSBLweFMWMEg3ej6FLSJT06kzH5yTAK7efxq ysJc6c/fzjeLMe5Ur83LWpp9LojqrxLDD3etMYMbmXapN4DsXl5gt9AU6HMOHo2F2nxG WfYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Wo8Thlm5; 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 a90si2574706pla.401.2019.03.20.12.13.46; Wed, 20 Mar 2019 12:14:01 -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=@joelfernandes.org header.s=google header.b=Wo8Thlm5; 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 S1726987AbfCTTL5 (ORCPT + 99 others); Wed, 20 Mar 2019 15:11:57 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:34331 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbfCTTL5 (ORCPT ); Wed, 20 Mar 2019 15:11:57 -0400 Received: by mail-qt1-f195.google.com with SMTP id k2so3930163qtm.1 for ; Wed, 20 Mar 2019 12:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=T3v6cngzSTNsn8JWqBXhJFmbZpKUUvu9y1fz3VFVogQ=; b=Wo8Thlm5mkrPj7z6qHCnFi5t+y9+HMHs9kz02t7qC6kxehEb3BoMtYkvoSqroRlynd QPTbpy2BNI8ptMcfoRheWqMORJgB5DkD/ivJvrBkaWDSHv6PpP9b/eX+06tUOv3hh/Qb SbWedVPzqat04VYk94AmVRYP1FZ53s3H6v0eQ= 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=T3v6cngzSTNsn8JWqBXhJFmbZpKUUvu9y1fz3VFVogQ=; b=WM0M8mWk2OYlbQ+8ajn5tHxhS1xc6ezGeu+4jB61Yf50CwQG9yYv5+XjevMd+HRsN/ 7ZkGZG2ItBbxC2hI7+Ffbqst8kKUU5iNp3PBFEoQpvoZazzkTq1/EcYK7+roqEDXJQnv +1M8FCeihQYjFChH54xJxtI5g3pUrEebpfrdKMSYaD9cmZjHQbJaDDVFvWSIyLNskCBY qzmnYRUkVUsSUOVMTfrluzXtTxwqG9KVZ9TITSODHq2F3laa1yUyRj6kz5wrCBFcAfKt 96b1CZFRHFeRSkpbQzqaZPof5qZeRyMjVjT2EPacaz1qI+QtBdflQdtMk4MzhI5kcKlL X4ZQ== X-Gm-Message-State: APjAAAWxAz/r2hoS8pY96bppFxwUCF0l+M2hVn1LcioQBpqH86fZEBFV S6LouW/dXnLdQj61cNgcbTCqvA== X-Received: by 2002:a0c:c784:: with SMTP id k4mr8044586qvj.90.1553109115827; Wed, 20 Mar 2019 12:11:55 -0700 (PDT) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id t73sm1992691qki.49.2019.03.20.12.11.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 12:11:54 -0700 (PDT) Date: Wed, 20 Mar 2019 15:11:53 -0400 From: Joel Fernandes To: Christian Brauner Cc: Daniel Colascione , Suren Baghdasaryan , Steven Rostedt , Sultan Alsawaf , Tim Murray , Michal Hocko , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Ingo Molnar , Peter Zijlstra , LKML , "open list:ANDROID DRIVERS" , linux-mm , kernel-team , Oleg Nesterov , Andy Lutomirski , "Serge E. Hallyn" , Kees Cook Subject: Re: pidfd design Message-ID: <20190320191153.GA76715@google.com> References: <20190318235052.GA65315@google.com> <20190319221415.baov7x6zoz7hvsno@brauner.io> <20190319231020.tdcttojlbmx57gke@brauner.io> <20190320015249.GC129907@google.com> <20190320035953.mnhax3vd47ya4zzm@brauner.io> <4A06C5BB-9171-4E70-BE31-9574B4083A9F@joelfernandes.org> <20190320182649.spryp5uaeiaxijum@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190320182649.spryp5uaeiaxijum@brauner.io> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 20, 2019 at 07:26:50PM +0100, Christian Brauner wrote: > On Wed, Mar 20, 2019 at 07:33:51AM -0400, Joel Fernandes wrote: > > > > > > On March 20, 2019 3:02:32 AM EDT, Daniel Colascione wrote: > > >On Tue, Mar 19, 2019 at 8:59 PM Christian Brauner > > > wrote: > > >> > > >> On Tue, Mar 19, 2019 at 07:42:52PM -0700, Daniel Colascione wrote: > > >> > On Tue, Mar 19, 2019 at 6:52 PM Joel Fernandes > > > wrote: > > >> > > > > >> > > On Wed, Mar 20, 2019 at 12:10:23AM +0100, Christian Brauner > > >wrote: > > >> > > > On Tue, Mar 19, 2019 at 03:48:32PM -0700, Daniel Colascione > > >wrote: > > >> > > > > On Tue, Mar 19, 2019 at 3:14 PM Christian Brauner > > > wrote: > > >> > > > > > So I dislike the idea of allocating new inodes from the > > >procfs super > > >> > > > > > block. I would like to avoid pinning the whole pidfd > > >concept exclusively > > >> > > > > > to proc. The idea is that the pidfd API will be useable > > >through procfs > > >> > > > > > via open("/proc/") because that is what users expect > > >and really > > >> > > > > > wanted to have for a long time. So it makes sense to have > > >this working. > > >> > > > > > But it should really be useable without it. That's why > > >translate_pid() > > >> > > > > > and pidfd_clone() are on the table. What I'm saying is, > > >once the pidfd > > >> > > > > > api is "complete" you should be able to set CONFIG_PROCFS=N > > >- even > > >> > > > > > though that's crazy - and still be able to use pidfds. This > > >is also a > > >> > > > > > point akpm asked about when I did the pidfd_send_signal > > >work. > > >> > > > > > > >> > > > > I agree that you shouldn't need CONFIG_PROCFS=Y to use > > >pidfds. One > > >> > > > > crazy idea that I was discussing with Joel the other day is > > >to just > > >> > > > > make CONFIG_PROCFS=Y mandatory and provide a new > > >get_procfs_root() > > >> > > > > system call that returned, out of thin air and independent of > > >the > > >> > > > > mount table, a procfs root directory file descriptor for the > > >caller's > > >> > > > > PID namspace and suitable for use with openat(2). > > >> > > > > > >> > > > Even if this works I'm pretty sure that Al and a lot of others > > >will not > > >> > > > be happy about this. A syscall to get an fd to /proc? > > >> > > > >> > Why not? procfs provides access to a lot of core kernel > > >functionality. > > >> > Why should you need a mountpoint to get to it? > > >> > > > >> > > That's not going > > >> > > > to happen and I don't see the need for a separate syscall just > > >for that. > > >> > > > >> > We need a system call for the same reason we need a getrandom(2): > > >you > > >> > have to bootstrap somehow when you're in a minimal environment. > > >> > > > >> > > > (I do see the point of making CONFIG_PROCFS=y the default btw.) > > >> > > > >> > I'm not proposing that we make CONFIG_PROCFS=y the default. I'm > > >> > proposing that we *hardwire* it as the default and just declare > > >that > > >> > it's not possible to build a Linux kernel that doesn't include > > >procfs. > > >> > Why do we even have that button? > > >> > > > >> > > I think his point here was that he wanted a handle to procfs no > > >matter where > > >> > > it was mounted and then can later use openat on that. Agreed that > > >it may be > > >> > > unnecessary unless there is a usecase for it, and especially if > > >the /proc > > >> > > directory being the defacto mountpoint for procfs is a universal > > >convention. > > >> > > > >> > If it's a universal convention and, in practice, everyone needs > > >proc > > >> > mounted anyway, so what's the harm in hardwiring CONFIG_PROCFS=y? > > >If > > >> > we advertise /proc as not merely some kind of optional debug > > >interface > > >> > but *the* way certain kernel features are exposed --- and there's > > >> > nothing wrong with that --- then we should give programs access to > > >> > these core kernel features in a way that doesn't depend on > > >userspace > > >> > kernel configuration, and you do that by either providing a > > >> > procfs-root-getting system call or just hardwiring the "/proc/" > > >prefix > > >> > into VFS. > > >> > > > >> > > > Inode allocation from the procfs mount for the file descriptors > > >Joel > > >> > > > wants is not correct. Their not really procfs file descriptors > > >so this > > >> > > > is a nack. We can't just hook into proc that way. > > >> > > > > >> > > I was not particular about using procfs mount for the FDs but > > >that's the only > > >> > > way I knew how to do it until you pointed out anon_inode (my grep > > >skills > > >> > > missed that), so thank you! > > >> > > > > >> > > > > C'mon: /proc is used by everyone today and almost every > > >program breaks > > >> > > > > if it's not around. The string "/proc" is already de facto > > >kernel ABI. > > >> > > > > Let's just drop the pretense of /proc being optional and bake > > >it into > > >> > > > > the kernel proper, then give programs a way to get to /proc > > >that isn't > > >> > > > > tied to any particular mount configuration. This way, we > > >don't need a > > >> > > > > translate_pid(), since callers can just use procfs to do the > > >same > > >> > > > > thing. (That is, if I understand correctly what translate_pid > > >does.) > > >> > > > > > >> > > > I'm not sure what you think translate_pid() is doing since > > >you're not > > >> > > > saying what you think it does. > > >> > > > Examples from the old patchset: > > >> > > > translate_pid(pid, ns, -1) - get pid in our pid namespace > > >> > > > >> > Ah, it's a bit different from what I had in mind. It's fair to want > > >to > > >> > translate PIDs between namespaces, but the only way to make the > > >> > translate_pid under discussion robust is to have it accept and > > >produce > > >> > pidfds. (At that point, you might as well call it translate_pidfd.) > > >We > > >> > should not be adding new APIs to the kernel that accept numeric > > >PIDs: > > >> > > >> The traditional pid-based api is not going away. There are users that > > >> have the requirement to translate pids between namespaces and also > > >doing > > >> introspection on these namespaces independent of pidfds. We will not > > >> restrict the usefulness of this syscall by making it only work with > > >> pidfds. > > >> > > >> > it's not possible to use these APIs correctly except under very > > >> > limited circumstances --- mostly, talking about init or a parent > > >> > > >> The pid-based api is one of the most widely used apis of the kernel > > >and > > >> people have been using it quite successfully for a long time. Yes, > > >it's > > >> rac, but it's here to stay. > > >> > > >> > talking about its child. > > >> > > > >> > Really, we need a few related operations, and we shouldn't > > >necessarily > > >> > mingle them. > > >> > > >> Yes, we've established that previously. > > >> > > >> > > > >> > 1) Given a numeric PID, give me a pidfd: that works today: you just > > >> > open /proc/ > > >> > > >> Agreed. > > >> > > >> > > > >> > 2) Given a pidfd, give me a numeric PID: that works today: you just > > >> > openat(pidfd, "stat", O_RDONLY) and read the first token (which is > > >> > always the numeric PID). > > >> > > >> Agreed. > > >> > > >> > > > >> > 3) Given a pidfd, send a signal: that's what pidfd_send_signal > > >does, > > >> > and it's a good start on the rest of these operations. > > >> > > >> Agreed. > > >> > > >> > 5) Given a pidfd in NS1, get a pidfd in NS2. That's what > > >translate_pid > > >> > is for. My preferred signature for this routine is > > >translate_pid(int > > >> > pidfd, int nsfd) -> pidfd. We don't need two namespace arguments. > > >Why > > >> > not? Because the pidfd *already* names a single process, uniquely! > > >> > > >> Given that people are interested in pids we can't just always return > > >a > > >> pidfd. That would mean a user would need to do get the pidfd read > > >from > > >> /stat and then close the pidfd. If you do that for a 100 pids > > >or > > >> more you end up allocating and closing file descriptors constantly > > >for > > >> no reason. We can't just debate pids away. So it will also need to be > > >> able to yield pids e.g. through a flag argument. > > > > > >Sure, but that's still not a reason that we should care about pidfds > > >working separately from procfs.. > > That's unrelated to the point made in the above paragraph. > Please note, I said that the pidfd api should work when proc is not > available not that they can't be dirfds. > > > > > Agreed. I can't imagine pidfd being anything but a proc pid directory handle. So I am confused what Christian meant. Pidfd *is* a procfs directory fid always. That's what I gathered from his pidfd_send_signal patch but let me know if I'm way off in the woods. > > (K9 Mail still hasn't learned to wrap lines at 80 it seems. :)) Indeed, or I misconfigured it :) Just set it up recently so I'm still messing with it. The other issue is it does wrapping on quoted lines too, and there's a bug filed somewhere for that. > Again, I never said that pidfds should be a directory handle. > (Though I would like to point out that one of the original ideas I > discussed at LPC was to have something like this to get regular file > descriptors instead of dirfds: > https://gist.github.com/brauner/59eec91550c5624c9999eaebd95a70df) Ok. I was just going by this code in your send_signal patch where you error out if the pidfd is not a directory. +struct pid *tgid_pidfd_to_pid(const struct file *file) +{ + if (!d_is_dir(file->f_path.dentry) || + (file->f_op != &proc_tgid_base_operations)) + return ERR_PTR(-EBADF); > > For my next revision, I am thinking of adding the flag argument Christian mentioned to make translate_pid return an anon_inode FD which can be used for death status, given a . Since it is thought that translate_pid can be made to return a pid FD, I think it is ok to have it return a pid status FD for the purposes of the death status as well. > > translate_pid() should just return you a pidfd. Having it return a pidfd > and a status fd feels like stuffing too much functionality in there. If > you're fine with it I'll finish prototyping what I had in mind. As I > said in previous mails I'm already working on this. Yes, please continue to work on it. No problem. > Would you be ok with prototyping the pidfd_wait() syscall you had in > mind? Yes, Of course, I am working on it. No problem. It is still good to discuss these ideas and to know what my direction should be, so I appreciate the conversation here. > Especially the wait_fd part that you want to have I would like to > see how that is supposed to work, e.g. who is allowed to wait on the > process and how notifications will work for non-parent processes and so > on. I feel we won't get anywhere by talking in the abstrace and other > people are far more likely to review/comment once there's actual code. Got it. Lets chat more once I post something. thanks, - Joel