Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4364543ybp; Mon, 14 Oct 2019 03:33:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmpQ+mVQxqVLfuJlpGUQZmNfyYcc+SP9E9bxxJYLqDjEtVRPPZXUpaULnA9X1tTDnyIehI X-Received: by 2002:aa7:d582:: with SMTP id r2mr20761183edq.196.1571049199885; Mon, 14 Oct 2019 03:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571049199; cv=none; d=google.com; s=arc-20160816; b=kqwOVyyuhWzMeMtGJbYdbKk2Ic326EGP5Otaax+1shVaYhof+7rsJp/Y7ftLf0zrce 25L/sIb3beb+hrvGA+eOfGHPXIesWgPnkI1PwGoz29xd9O3VI/T6tuBwiyV9VvNYrM2k cF2w7hAjh4NxHyI79/Ka7GGkHfzSlIYHr/WPajDW+rFUqHSMBexTP9krI8lVE+xbQmRW ZWNIhDAoMKZjAXwkUsT+Gz2bV/CdG+Rg0Kjfm3XRRFHbGpovfwgFYFeUiRPDwTbaRWB4 +5NRJL8ync08OIRTNLRyEqWiUiF3+uaI2ke35HHC/h/uC8qNCN1pD5n/QttHhl+eZzlR jcVA== 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=mJip0/jbrgvv+snVbFjM9KZlQ3m8OztYx5oaY+mCnHI=; b=OcqRkYtOhZ4Ec3DEHpZnnvH5vq38Zi75d0JGyDDrKsjQhfZg3LKN66J/tpThGIZjxv PFtOD6pz+nM6xMZtha5iKCohHD09CFXyBSgNJGGqG7983JQBQ8nJsPzQj90s9pokpYO/ 5ANPTV5Zo9B5hndv3qzcqL2/IVjmiZg70D/x6w8n6ouN9wYcFgkbZQ1o0ppSo1u4ZyDb ZVVoHJveQFGKAb7rRYBzP5WlAOQ5JSZ1fmRsUCXHIruIsYw3uRX8HsKT0RM6OndqP3g6 XoFQVpJf9KJ8BsClTnfmZss3Ab/zYr0jQk+iNLrdGnj/AiGjL8+iXKgdu1xmnNt7u9zd Dn9A== 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 k7si11376134edb.238.2019.10.14.03.32.56; Mon, 14 Oct 2019 03:33:19 -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 S1731462AbfJNKcJ (ORCPT + 99 others); Mon, 14 Oct 2019 06:32:09 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:34117 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731127AbfJNKcI (ORCPT ); Mon, 14 Oct 2019 06:32:08 -0400 Received: from [212.86.36.32] (helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iJxdv-0001ho-5b; Mon, 14 Oct 2019 10:31:59 +0000 Date: Mon, 14 Oct 2019 12:31:58 +0200 From: Christian Brauner To: Christian Kellner Cc: jannh@google.com, aarcange@redhat.com, akpm@linux-foundation.org, cyphar@cyphar.com, elena.reshetova@intel.com, guro@fb.com, ldv@altlinux.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, viro@zeniv.linux.org.uk Subject: Re: [PATCH] pidfd: add NSpid entries to fdinfo Message-ID: <20191014103157.h2wph2ujjidsrhyw@wittgenstein> References: <20191012101922.24168-1-christian.brauner@ubuntu.com> <20191012102119.qq2adlnxjxrkslca@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 14, 2019 at 11:43:01AM +0200, Christian Kellner wrote: > On Sat, 2019-10-12 at 12:21 +0200, Christian Brauner wrote: > > I think this might be more what we want. > Yep, indeed. > > > I tried to think of cases where the first entry of Pid is not > > identical > > to the first entry of NSpid but I came up with none. Maybe you do, > > Jann? > Yeah, I don't think that can be the case. By looking at the source of > 'pid_nr_ns(pid, ns)' a non-zero return means that a) 'pid' valid, ie. > non-null and b) 'ns' is in the pid namespace hierarchy of 'pid' (at > pid->level, i.e. "pid->numbers[ns->level].ns == ns"). > > > Christian, this is just a quick stab I took. Feel free to pick this > > up as a template. > Thanks! I slightly re-worked it, with the reasoning above in mind, to > get rid of one of the branches: Thanks! > > +#ifdef CONFIG_PID_NS > + seq_put_decimal_ull(m, "\nNSpid:\t", nr); > + if (nr) { > + int i; > + > + /* If nr is non-zero it means that 'pid' is valid and that > + * ns, i.e. the pid namespace associated with the procfs > + * instance, is in the pid namespace hierarchy of pid. > + * Start at one level below and print all descending pids. > + */ > + for (i = ns->level + 1; i <= pid->level; i++) { > + ns = pid->numbers[i].ns; I'm not a fan of overriding the "ns" pointer. It's not a huge deal but it's rather subtle. > + seq_put_decimal_ull(m, "\t", pid_nr_ns(pid, ns)); > + } > + } > +#endif > > But I now just realized that with the very same reasoning, if nr is > non-zero, we don't need to redo all the checks and can just do: > > for (i = ns->level + 1; i <= pid->level; i++) > seq_put_decimal_ull(m, "\t", pid->numbers[i].nr); > > If this sounds good to you I resend the patches with the change above. You could probably do: #ifdef CONFIG_PID_NS seq_put_decimal_ull(m, "\nNSpid:\t", nr); for (i = ns->level + 1; i <= pid->level && nr; i++) seq_put_decimal_ull(m, "\t", pid->numbers[i].nr); #endif Christian