Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1218309ybp; Wed, 9 Oct 2019 10:31:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqo1PZc42HMxlj2QsrO8hzZA2lMiSqxCcbWeb1emP/bzMb4SX0RoQJ1iQbTXI+bTMUAVii X-Received: by 2002:a17:906:2cd4:: with SMTP id r20mr3881170ejr.307.1570642290101; Wed, 09 Oct 2019 10:31:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570642290; cv=none; d=google.com; s=arc-20160816; b=okUwHzxDBEE9k5cxhfCYxpJeccFjTfJRGv7eWEKv8eM6YVZWxl2nw5f5LJ2C65BuQ6 EKkHiVHklGpfPP6WMdzIKNDLFjfC1hTexyBK6UyhZaHi51szuERQ3679EvuS4j4GixuE mCXjUNfKioFHGGbho4Gjq0F5T2y7G4pCGE1fXp7WXCilqBS8sIAHy5lUcY5J9cLmbosx yZwdK5fJs1i9ay+Vgg/EDmQInFKCbXlAXofDOOX0jqLzyWVejt1i2QZnUYclr1J20LoN qpt3zd8rS6D+HeYPjAvCmV63v1/Gw7eosgqxUQ/N53mV3x/Gl0M1MqvwjAffMDgEsxzN YrpA== 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; bh=5XPuqh2hUkmC63o5AOcKxKuYwg09qIhJQNvrgIr0ifI=; b=i+Zi1aztYSArckchqDyt1ZqbMpOHypv27/1274+mZUayMrBfrCbMEj9D6m7uv/wk4y iKk5CDYxmk0I92521vZKQA17NBET8oF4ekTUyxKyrLQNbA6wvwF/nkJvx7zGoyTfvPzk /KUtXeCdGhpdbeSw2Y8iyd2IOD9vV3x0eF1kHxKhONZLS3cy9+nQhlHYR8UVkP2M2lMA TZ0SFlqPoeP820XFXV54q2ncV+489Yr0CtoE+Y1gCTeU8a1CCYgvrhWZmt9aI45CTSij q0pSxDD9aa5sXvdtJ1UDvoPurKDhhXEAAbNh5pyfOTqgMPzFxD4xfHVKRmVNPW6DtmoS jtOQ== ARC-Authentication-Results: i=1; mx.google.com; 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 h48si1843985ede.31.2019.10.09.10.31.06; Wed, 09 Oct 2019 10:31:30 -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; 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 S1732899AbfJIR3v (ORCPT + 99 others); Wed, 9 Oct 2019 13:29:51 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49541 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732184AbfJIR3t (ORCPT ); Wed, 9 Oct 2019 13:29:49 -0400 Received: from [213.220.153.21] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iIFmU-0002kv-Qn; Wed, 09 Oct 2019 17:29:46 +0000 Date: Wed, 9 Oct 2019 19:29:46 +0200 From: Christian Brauner To: Christian Kellner Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, Christian Kellner , Christian Brauner , Andrew Morton , "Peter Zijlstra (Intel)" , Ingo Molnar , Michal Hocko , Elena Reshetova , Thomas Gleixner , Roman Gushchin , Andrea Arcangeli , "Joel Fernandes (Google)" , Al Viro , "Dmitry V. Levin" Subject: Re: [PATCH v2 1/2] pidfd: show pids for nested pid namespaces in fdinfo Message-ID: <20191009172944.if5x3rpkb54zs4ry@wittgenstein> References: <20191008133641.23019-1-ckellner@redhat.com> <20191009160532.20674-1-ckellner@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191009160532.20674-1-ckellner@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, Oct 09, 2019 at 06:05:30PM +0200, Christian Kellner wrote: > From: Christian Kellner > > The fdinfo file for a process file descriptor already contains the > pid of the process in the callers namespaces. Additionally, if pid > namespaces are configured, show the process ids of the process in > all nested namespaces in the same format as in the procfs status > file, i.e. "NSPid:\t%d\%d...". This allows the easy identification > of the processes in nested namespaces. > > Signed-off-by: Christian Kellner > --- > > Changes in v2: > - Moved into separate function to avoid multiple ifdefs as suggested > by Michal Hocko > > kernel/fork.c | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/kernel/fork.c b/kernel/fork.c > index 5a0fd518e04e..f7a59ef046e9 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -1681,12 +1681,27 @@ static int pidfd_release(struct inode *inode, struct file *file) > } > > #ifdef CONFIG_PROC_FS > +static void pidfd_nspid(struct seq_file *m, struct pid *pid) If it has to be a separate helper then please make it: static inline void print_pidfd_nspid(struct seq_file *m, struct pid_namespace *ns, struct pid *pid) { #ifdef CONFIG_PID_NS int i; seq_puts(m, "\nNSpid:"); for (i = ns->level; i <= pid->level; i++) { ns = pid->numbers[i].ns; seq_put_decimal_ull(m, "\t", pid_nr_ns(pid, ns)); } #endif } It's called nowhere else and we've already retrieved the pid_namespace in pidfd_show_fdinfo(). > +{ > +#ifdef CONFIG_PID_NS > + struct pid_namespace *ns = proc_pid_ns(file_inode(m->file)); > + int i; > + > + seq_puts(m, "\nNSpid:"); > + for (i = ns->level; i <= pid->level; i++) { > + ns = pid->numbers[i].ns; > + seq_put_decimal_ull(m, "\t", pid_nr_ns(pid, ns)); > + } > +#endif > +} > + > static void pidfd_show_fdinfo(struct seq_file *m, struct file *f) > { > struct pid_namespace *ns = proc_pid_ns(file_inode(m->file)); > struct pid *pid = f->private_data; > > seq_put_decimal_ull(m, "Pid:\t", pid_nr_ns(pid, ns)); > + pidfd_nspid(m, pid); > seq_putc(m, '\n'); > } > #endif > -- > 2.21.0 >