Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1871130ybg; Thu, 30 Jul 2020 05:03:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3Wpy2rQCgXu7X0Es3cAyl/E2kmgEwFAGi3WipWa9FZR8CYRMzb5OYCM1YOEF861fRxOJL X-Received: by 2002:a17:907:444c:: with SMTP id on20mr2372882ejb.77.1596110621633; Thu, 30 Jul 2020 05:03:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596110621; cv=none; d=google.com; s=arc-20160816; b=hRD7PSBEiScsgYoJGKWZ+iIwXudFHOKKeseyvkTKplufZhocoHiFJfPr96cuOOCVMa 9H1jwofUbHY5HwCugOLmU+ld1OzJAgipbROfJLETiThfCYjQJFT/I7jRkiZWZ7My5a9+ J9+8Zg3+Dezw8h2mjjAJnCSSHJGaL3w/+hImA2NUXln7RX5CUAFk/clHJnfdztJgnJnT 99+O8RMy8oh7THzr1qIsuuam0wenDyMH4b2SDQ+Dp3kqu+SCmM3HXOhGuHVqHfIk7edF LtF7c2Aj/Ay5slSsIZ6kAjdI5DLlvRm3pVAVLMdkOJhbcK4nDADE9SKMkd/jq3MAM8Yv uDyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=3SGm2/6rvRs58d3nr+OPbXZ1bZy8bjwhxEak4uKndl4=; b=FqQJgEC1z40IdIFnmcPwjo+uB307paALItaANEzp1rWc3VKH2pmefOttFM144GajTG vVniomvnoMwVKIpjcnaC7fCLKQBflmne48b3NzTb0ooT73k/iTZx8ITY8NIbXVentMAd Gpjqjg5NVe6uRCdStqQcTUjMeps8fyxY2ALNbIbqqIja+5cJFb7jn4HyD3Ynvhrt1zgh 6Etp2hSevEm1RjmFiUHi/6DG4JIoM2k87cC2qM7lH6dXS9hKxTyg0f/0xwFtD3f0UbIa 3XYKN95fyyMyJpvcO6vOoyL6MgvZqkmoPknyHBLputS8t0MnQBwjov8u0B/nYgManwSF zrNw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e7si2167650ejm.580.2020.07.30.05.03.18; Thu, 30 Jul 2020 05:03:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728981AbgG3MBZ (ORCPT + 99 others); Thu, 30 Jul 2020 08:01:25 -0400 Received: from relay.sw.ru ([185.231.240.75]:57242 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728918AbgG3MBV (ORCPT ); Thu, 30 Jul 2020 08:01:21 -0400 Received: from [192.168.15.64] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k17FA-00030d-Pn; Thu, 30 Jul 2020 15:01:04 +0300 Subject: [PATCH 22/23] cgroup: Add cgroup namespaces into ns_idr From: Kirill Tkhai To: viro@zeniv.linux.org.uk, adobriyan@gmail.com, davem@davemloft.net, ebiederm@xmission.com, akpm@linux-foundation.org, christian.brauner@ubuntu.com, areber@redhat.com, serge@hallyn.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, ktkhai@virtuozzo.com Date: Thu, 30 Jul 2020 15:01:18 +0300 Message-ID: <159611047870.535980.3790860133632973446.stgit@localhost.localdomain> In-Reply-To: <159611007271.535980.15362304262237658692.stgit@localhost.localdomain> References: <159611007271.535980.15362304262237658692.stgit@localhost.localdomain> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now they are exposed in /proc/namespace/ directory. Signed-off-by: Kirill Tkhai --- include/linux/cgroup.h | 1 + kernel/cgroup/namespace.c | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 451c2d26a5db..38913d91fa92 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -858,6 +858,7 @@ struct cgroup_namespace { struct user_namespace *user_ns; struct ucounts *ucounts; struct css_set *root_cset; + struct rcu_head rcu; }; extern struct cgroup_namespace init_cgroup_ns; diff --git a/kernel/cgroup/namespace.c b/kernel/cgroup/namespace.c index f5e8828c109c..64393bbafb2c 100644 --- a/kernel/cgroup/namespace.c +++ b/kernel/cgroup/namespace.c @@ -39,11 +39,12 @@ static struct cgroup_namespace *alloc_cgroup_ns(void) void free_cgroup_ns(struct cgroup_namespace *ns) { + ns_idr_unregister(&ns->ns); put_css_set(ns->root_cset); dec_cgroup_namespaces(ns->ucounts); put_user_ns(ns->user_ns); ns_free_inum(&ns->ns); - kfree(ns); + kfree_rcu(ns, rcu); } EXPORT_SYMBOL(free_cgroup_ns); @@ -54,6 +55,7 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, struct cgroup_namespace *new_ns; struct ucounts *ucounts; struct css_set *cset; + int err; BUG_ON(!old_ns); @@ -78,16 +80,28 @@ struct cgroup_namespace *copy_cgroup_ns(unsigned long flags, new_ns = alloc_cgroup_ns(); if (IS_ERR(new_ns)) { - put_css_set(cset); - dec_cgroup_namespaces(ucounts); - return new_ns; + err = PTR_ERR(new_ns); + goto err_put_css_set; } new_ns->user_ns = get_user_ns(user_ns); new_ns->ucounts = ucounts; new_ns->root_cset = cset; + err = ns_idr_register(&new_ns->ns); + if (err < 0) + goto err_put_user_ns; + return new_ns; + +err_put_user_ns: + put_user_ns(new_ns->user_ns); + ns_free_inum(&new_ns->ns); + kfree(new_ns); +err_put_css_set: + put_css_set(cset); + dec_cgroup_namespaces(ucounts); + return ERR_PTR(err); } static inline struct cgroup_namespace *to_cg_ns(struct ns_common *ns) @@ -152,6 +166,7 @@ const struct proc_ns_operations cgroupns_operations = { static __init int cgroup_namespaces_init(void) { + WARN_ON(ns_idr_register(&init_cgroup_ns.ns) < 0); return 0; } subsys_initcall(cgroup_namespaces_init);