Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1942326pxa; Mon, 3 Aug 2020 03:19:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbA4R4Kx7GhbdUB7LnyxOrLW9zEjOtDw/xSc8ICmyXkBj+PYCoDaMDHx/yVZT3Nsprbp8H X-Received: by 2002:a05:6402:17a1:: with SMTP id j1mr14547969edy.99.1596449979848; Mon, 03 Aug 2020 03:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596449979; cv=none; d=google.com; s=arc-20160816; b=Ww+piCr3d/UuU9Eiz97SXszacqvnxsZZfIif0Hq+QUtl+6wW8o2ChZm838eL5r32+C sxs92pMMoQIRNK2vQvqfhjx974sFgoPZEHEyO6tqztLNULB332aNGA+cs8UPwOhltSee Use/BRpdtcRngZqU+OgIGh6KBju5ig9kH1/16KB4wiM6D5/QM9pmV9j47IW+qLaicjbY EWP7F0OXJwt5tXkO7dm+mgSvwLawMNoKRwT9kS30FSbzK0HeRPp7OAfLkZOhixkmy2Zb D1SXCIrKT8gWAa2OKoYqJjdUMOChADxWj3zMkwP/9C6Uo1uqRKCkk6ypOhaY0KR7Qqni Zppg== 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=r+qbyPWmed+Ro3BIZqIiyYKhMq3J98+3nZyq1Dl0Xpo=; b=waIFDDy66JF4dY2tw+xC5HKnj5d5tkgjSYJESCvMoSLqw6EmkBHoYn2elsA3tVtVkK ENLnygU9nfFvODx+4aRG61I8hfFax+WFv/D0jphWO2EJjj2p766d3ovKGPKZwvAGxK5W Pjn9pZnnPGXnSAyFyyYes2Us2a5PCOEKI2LdKcD22TmmLWlZjNrThtYsuKvZX0RfSc4s XtI9RuBT8VTsdcyAV2f16ZQ9v9svU/ae2Pr1zaAZrjO7PZADZsDcAZk18qXF+W8VxuYm ZDSpYE9h6YNjLo/vOTMdUzLqGFJToA50J1nGCUhRRuy1nqffuhbAGSSJ/OUEYjxz1fnn br8g== 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 bh13si10294301ejb.48.2020.08.03.03.19.17; Mon, 03 Aug 2020 03:19:39 -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 S1726606AbgHCKQf (ORCPT + 99 others); Mon, 3 Aug 2020 06:16:35 -0400 Received: from relay.sw.ru ([185.231.240.75]:37816 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725951AbgHCKQf (ORCPT ); Mon, 3 Aug 2020 06:16:35 -0400 Received: from [192.168.15.50] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k2XVr-0002Nw-Oz; Mon, 03 Aug 2020 13:16:11 +0300 Subject: [PATCH 4/8] pid: Use generic ns_common::count From: Kirill Tkhai To: christian.brauner@ubuntu.com, akpm@linux-foundation.org, ebiederm@xmission.com, viro@zeniv.linux.org.uk, adobriyan@gmail.com, davem@davemloft.net, linux-kernel@vger.kernel.org, ktkhai@virtuozzo.com Date: Mon, 03 Aug 2020 13:16:32 +0300 Message-ID: <159644979226.604812.7512601754841882036.stgit@localhost.localdomain> In-Reply-To: <159644958332.604812.13004003379291842292.stgit@localhost.localdomain> References: <159644958332.604812.13004003379291842292.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 Convert pid namespace to use generic counter. Signed-off-by: Kirill Tkhai Acked-by: Christian Brauner --- include/linux/pid_namespace.h | 4 +--- kernel/pid.c | 2 +- kernel/pid_namespace.c | 13 +++---------- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index 5a5cb45ac57e..7c7e627503d2 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -8,7 +8,6 @@ #include #include #include -#include #include #include @@ -18,7 +17,6 @@ struct fs_pin; struct pid_namespace { - struct kref kref; struct idr idr; struct rcu_head rcu; unsigned int pid_allocated; @@ -43,7 +41,7 @@ extern struct pid_namespace init_pid_ns; static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns) { if (ns != &init_pid_ns) - kref_get(&ns->kref); + refcount_inc(&ns->ns.count); return ns; } diff --git a/kernel/pid.c b/kernel/pid.c index de9d29c41d77..3b9e67736ef4 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -72,7 +72,7 @@ int pid_max_max = PID_MAX_LIMIT; * the scheme scales to up to 4 million PIDs, runtime. */ struct pid_namespace init_pid_ns = { - .kref = KREF_INIT(2), + .ns.count = REFCOUNT_INIT(2), .idr = IDR_INIT(init_pid_ns.idr), .pid_allocated = PIDNS_ADDING, .level = 0, diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c index 0e5ac162c3a8..d02dc1696edf 100644 --- a/kernel/pid_namespace.c +++ b/kernel/pid_namespace.c @@ -102,7 +102,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns goto out_free_idr; ns->ns.ops = &pidns_operations; - kref_init(&ns->kref); + refcount_set(&ns->ns.count, 1); ns->level = level; ns->parent = get_pid_ns(parent_pid_ns); ns->user_ns = get_user_ns(user_ns); @@ -148,22 +148,15 @@ struct pid_namespace *copy_pid_ns(unsigned long flags, return create_pid_namespace(user_ns, old_ns); } -static void free_pid_ns(struct kref *kref) -{ - struct pid_namespace *ns; - - ns = container_of(kref, struct pid_namespace, kref); - destroy_pid_namespace(ns); -} - void put_pid_ns(struct pid_namespace *ns) { struct pid_namespace *parent; while (ns != &init_pid_ns) { parent = ns->parent; - if (!kref_put(&ns->kref, free_pid_ns)) + if (!refcount_dec_and_test(&ns->ns.count)) break; + destroy_pid_namespace(ns); ns = parent; } }