Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp52115img; Tue, 19 Mar 2019 15:27:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqynqCL/QV2HWmcSmFZzCUjXu2zQilQpj9JEUhKbfDV0jcIDusmd6C/IZEJMJ6EwLyIKoGeh X-Received: by 2002:a62:1c87:: with SMTP id c129mr4231320pfc.94.1553034475018; Tue, 19 Mar 2019 15:27:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553034475; cv=none; d=google.com; s=arc-20160816; b=GUQ0bELztUhz9A9ED0kVuYaDbAVT85PriB0FUMxpfEQmKHRcxvISsSYd0RbAP1DYi/ nHcaQCoJaasHma6yYT1hS4p8+wLGkrET9yoX4hHnVJy0MDVI1bykLhnFLcDvdlggZvQp dy7zWauXtpDWJqYNBxHmg7Nti5dJqDxPXwAg45fB7lxXXhprfHSPD3Q9lzbMsfx7YjrB okC6lR39RaMnod/s0xmp2vfgd84Rz/VHouKUVwR9DYQ4rbKj6WpESIyNWx1aytx5HSvC PLevfrZOic/eNL8WkNcMczBZzBev54ZVCTXCvxB+a6hry2Y82mpEC5RZ7x7RTjXAuWX8 xwlA== 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=HzoYzrsLg5B5gLgKw7GHM9JbUp9EVXgL6mdkso+jioQ=; b=qh6reaLQKXZJbtG35MHx8jAHKZiOnW5rN7xFukHVjIn2Y/qOx86r9GgRztaW5TaTub dy8S08sS6J1aDNm4hsBFoAP4TCEudrDu5tX8qXDGZWPdfOo7lw3HJNtpMIZ6ACzbp9A/ 9LK/6bv0qhIxhAMXKyluwELv/cdUEyjnO1Iie1YICeWa7Il0xHuMSTHM8GxCA9xMlTnu ndQshPtT8sAYz1eHxwaeJDDPVML5y5/2z48T3etwj7Ro6tFsunMaUo5rJNbuy4nlmgLb tmrloyDc28xAXB2WJZgn5qQ+uiFg18FJXcX26V1SxGRR0kaxVGKGoX0d+DCEN3nkCzOt 5NBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=A2gNd4cL; 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 w3si186486pll.417.2019.03.19.15.27.39; Tue, 19 Mar 2019 15:27:55 -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=A2gNd4cL; 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 S1727000AbfCSW04 (ORCPT + 99 others); Tue, 19 Mar 2019 18:26:56 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:35085 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726851AbfCSW04 (ORCPT ); Tue, 19 Mar 2019 18:26:56 -0400 Received: by mail-qt1-f195.google.com with SMTP id h39so344564qte.2 for ; Tue, 19 Mar 2019 15:26:55 -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=HzoYzrsLg5B5gLgKw7GHM9JbUp9EVXgL6mdkso+jioQ=; b=A2gNd4cLJocGajWw4GyY+/GHddeivArYInHbh3QIoc3viu0SEoXje37+SKbckdtf15 GH8GRMiNxYwzTx7YQR7rCXuC140wfyc02yiDTW4dhU2FtrSI0fmZuXJqym4oiEFQPsJo HKglpYCUHvJtDZApXm7JFkx2GI3MpxWI8cVhA= 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=HzoYzrsLg5B5gLgKw7GHM9JbUp9EVXgL6mdkso+jioQ=; b=recsx3tBkROzJ+ClDDSyBr6kWmen7dbV4iw8SVxeSrFiKTmckS0m/acjf3HxKJ6c/E RsDndYkdHcMPfdA5CFCm/xX5xuP8NNZCEhqWk49+VRPyMQYQg5DIOqDndrimLUzSe0wN QS0zrYMu8x+lRTLe3nDpRxTUc8X659OOs3BNniPRLHd/X/zMwZERrE1XjrxGS/WvBN/9 T/uVwk/tsnIhY/gaJni7LEPn5izx+qVfKNfqr5OzLmPKo+7TaO6bQBcIHoQ5PYEJwvfH UkHuIBeOXRGc1ZVL4CzBenacwdiWLy8YuM2GMEFVXfq3RmEG61zLJQzm7ZY9TK3BXl5X blMw== X-Gm-Message-State: APjAAAXN6mQYzvUC619vcokD1VYW3vrgh5EK3vIXNb4a8StRgoTrV2XF pQhhjcauICN2lPAiHVHvBmm6cA== X-Received: by 2002:a0c:d07b:: with SMTP id d56mr3903106qvh.89.1553034414443; Tue, 19 Mar 2019 15:26:54 -0700 (PDT) Received: from localhost ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id n24sm159631qtc.21.2019.03.19.15.26.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 19 Mar 2019 15:26:53 -0700 (PDT) Date: Tue, 19 Mar 2019 18:26:52 -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" , keescook@chromium.org Subject: Re: [RFC] simple_lmk: Introduce Simple Low Memory Killer for Android Message-ID: <20190319222652.GA105485@google.com> References: <20190316185726.jc53aqq5ph65ojpk@brauner.io> <20190317015306.GA167393@google.com> <20190317114238.ab6tvvovpkpozld5@brauner.io> <20190318002949.mqknisgt7cmjmt7n@brauner.io> <20190318235052.GA65315@google.com> <20190319221415.baov7x6zoz7hvsno@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190319221415.baov7x6zoz7hvsno@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 Tue, Mar 19, 2019 at 11:14:17PM +0100, Christian Brauner wrote: [snip] > > > > ---8<----------------------- > > > > From: Joel Fernandes > > Subject: [PATCH] Partial skeleton prototype of pidfd_wait frontend > > > > Signed-off-by: Joel Fernandes > > --- > > arch/x86/entry/syscalls/syscall_32.tbl | 1 + > > arch/x86/entry/syscalls/syscall_64.tbl | 1 + > > include/linux/syscalls.h | 1 + > > include/uapi/asm-generic/unistd.h | 4 +- > > kernel/signal.c | 62 ++++++++++++++++++++++++++ > > kernel/sys_ni.c | 3 ++ > > 6 files changed, 71 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl > > index 1f9607ed087c..2a63f1896b63 100644 > > --- a/arch/x86/entry/syscalls/syscall_32.tbl > > +++ b/arch/x86/entry/syscalls/syscall_32.tbl > > @@ -433,3 +433,4 @@ > > 425 i386 io_uring_setup sys_io_uring_setup __ia32_sys_io_uring_setup > > 426 i386 io_uring_enter sys_io_uring_enter __ia32_sys_io_uring_enter > > 427 i386 io_uring_register sys_io_uring_register __ia32_sys_io_uring_register > > +428 i386 pidfd_wait sys_pidfd_wait __ia32_sys_pidfd_wait > > diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl > > index 92ee0b4378d4..cf2e08a8053b 100644 > > --- a/arch/x86/entry/syscalls/syscall_64.tbl > > +++ b/arch/x86/entry/syscalls/syscall_64.tbl > > @@ -349,6 +349,7 @@ > > 425 common io_uring_setup __x64_sys_io_uring_setup > > 426 common io_uring_enter __x64_sys_io_uring_enter > > 427 common io_uring_register __x64_sys_io_uring_register > > +428 common pidfd_wait __x64_sys_pidfd_wait > > > > # > > # x32-specific system call numbers start at 512 to avoid cache impact > > diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h > > index e446806a561f..62160970ed3f 100644 > > --- a/include/linux/syscalls.h > > +++ b/include/linux/syscalls.h > > @@ -988,6 +988,7 @@ asmlinkage long sys_rseq(struct rseq __user *rseq, uint32_t rseq_len, > > asmlinkage long sys_pidfd_send_signal(int pidfd, int sig, > > siginfo_t __user *info, > > unsigned int flags); > > +asmlinkage long sys_pidfd_wait(int pidfd); > > > > /* > > * Architecture-specific system calls > > diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h > > index dee7292e1df6..137aa8662230 100644 > > --- a/include/uapi/asm-generic/unistd.h > > +++ b/include/uapi/asm-generic/unistd.h > > @@ -832,9 +832,11 @@ __SYSCALL(__NR_io_uring_setup, sys_io_uring_setup) > > __SYSCALL(__NR_io_uring_enter, sys_io_uring_enter) > > #define __NR_io_uring_register 427 > > __SYSCALL(__NR_io_uring_register, sys_io_uring_register) > > +#define __NR_pidfd_wait 428 > > +__SYSCALL(__NR_pidfd_wait, sys_pidfd_wait) > > > > #undef __NR_syscalls > > -#define __NR_syscalls 428 > > +#define __NR_syscalls 429 > > > > /* > > * 32 bit systems traditionally used different > > diff --git a/kernel/signal.c b/kernel/signal.c > > index b7953934aa99..ebb550b87044 100644 > > --- a/kernel/signal.c > > +++ b/kernel/signal.c > > @@ -3550,6 +3550,68 @@ static int copy_siginfo_from_user_any(kernel_siginfo_t *kinfo, siginfo_t *info) > > return copy_siginfo_from_user(kinfo, info); > > } > > > > +static ssize_t pidfd_wait_read_iter(struct kiocb *iocb, struct iov_iter *to) > > +{ > > + /* > > + * This is just a test string, it will contain the actual > > + * status of the pidfd in the future. > > + */ > > + char buf[] = "status"; > > + > > + return copy_to_iter(buf, strlen(buf)+1, to); > > +} > > + > > +static const struct file_operations pidfd_wait_file_ops = { > > + .read_iter = pidfd_wait_read_iter, > > +}; > > + > > +static struct inode *pidfd_wait_get_inode(struct super_block *sb) > > +{ > > + struct inode *inode = new_inode(sb); > > + > > + inode->i_ino = get_next_ino(); > > + inode_init_owner(inode, NULL, S_IFREG); > > + > > + inode->i_op = &simple_dir_inode_operations; > > + inode->i_fop = &pidfd_wait_file_ops; > > + > > + return inode; > > +} > > + > > +SYSCALL_DEFINE1(pidfd_wait, int, pidfd) > > +{ > > + struct fd f; > > + struct inode *inode; > > + struct file *file; > > + int new_fd; > > + struct pid_namespace *pid_ns; > > + struct super_block *sb; > > + struct vfsmount *mnt; > > + > > + f = fdget_raw(pidfd); > > + if (!f.file) > > + return -EBADF; > > + > > + sb = file_inode(f.file)->i_sb; > > + pid_ns = sb->s_fs_info; > > + > > + inode = pidfd_wait_get_inode(sb); > > + > > + mnt = pid_ns->proc_mnt; > > + > > + file = alloc_file_pseudo(inode, mnt, "pidfd_wait", O_RDONLY, > > + &pidfd_wait_file_ops); > > 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. Oh, ok. Somehow 'proc' and 'pid' sound very similar in terminology so naturally I felt the proc fs superblock would be a fit, but I see your point. > So instead of going throught proc we should probably do what David has > been doing in the mount API and come to rely on anone_inode. So > something like: > > fd = anon_inode_getfd("pidfd", &pidfd_fops, file_priv_data, flags); > > and stash information such as pid namespace etc. in a pidfd struct or > something that we then can stash file->private_data of the new file. > This also lets us avoid all this open coding done here. > Another advantage is that anon_inodes is its own kernel-internal > filesystem. Thanks for the suggestion! Agreed this is better and will do it this way then. thanks, - Joel