Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1941345pxa; Mon, 3 Aug 2020 03:17:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx79mp6bBvJz8QPylPbj7bj/IyGkvf+/waPVV2ZPni/V86BDBYkxqnCvoXn+zFQ4a+ecDN9 X-Received: by 2002:aa7:c0d8:: with SMTP id j24mr15287150edp.338.1596449874792; Mon, 03 Aug 2020 03:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596449874; cv=none; d=google.com; s=arc-20160816; b=UidO7C1aDVOO0gJcyIb5xCw6WjYjwxsqG1AtGzZemB6s+1RFbhOB0gIBo13IajYkRi w/34MEmyjdwVbwcnZ6IK/QDjJGMRI9LG7X0gr6elrQ1rEjllIUUOaijMuzJQEi1BjD8q obOJxry6Fvw6Lk99bi1iVsWetHAaBVKrcqCdtJUOYj+EJSs5jpN83jwMa52Kt9jwqWGg /Ref8gRga3xjW8Fk6RkIKokZu4glLem8Sb2JjP+QwBBmJQ7apyj0AzDOaN8jNAWjynJx VNc5lSUteHL8Aw/TvacBt7/CiLndRNZ/ysvHxcbCvW8qkFzSzf1xvlXifPQlDBGS8nVL LreA== 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=0UDVJVr/c6HivziCkdyubi35+vdCF80uYuH0e5sS8Gs=; b=XBchCGydUvH7Usj6NB0r+ljQHkEm19y4BwYMSWA9sgdZ6MJEj+dYWBEcdlK7MsJSbx cqU5oPs54hzz1/mHsNofGxgYTbRf0cl/tShlsWPBFDA4dN1CmwLFhi2aFuc1F3JG4N4W oGkGfj8b6LrfwcoUneLMOYsVj9UJxHg4oNy/rmsVhYlYR2WgLfmbtXL0jYU8i2Atf7mP pkhy2xs7NNDc1rBfHNE9a+zc3HTgnNZB0dXPGizNpD30DtagGby4p+1tzc4Z9zW06Y4G C9o3QR0z2wNV2IZ7qHpmvu2iL+Y4bXk8TsKEsdf7D/Mr+tBkRyoDSJcZAHjB8N3LS5ao lTSA== 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 v6si10180792eju.570.2020.08.03.03.17.32; Mon, 03 Aug 2020 03:17:54 -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 S1726631AbgHCKQk (ORCPT + 99 others); Mon, 3 Aug 2020 06:16:40 -0400 Received: from relay.sw.ru ([185.231.240.75]:37838 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725951AbgHCKQk (ORCPT ); Mon, 3 Aug 2020 06:16:40 -0400 Received: from [192.168.15.50] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k2XVx-0002O7-37; Mon, 03 Aug 2020 13:16:17 +0300 Subject: [PATCH 5/8] user: 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:37 +0300 Message-ID: <159644979754.604812.601625186726406922.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 user namespace to use generic counter. Signed-off-by: Kirill Tkhai Acked-by: Christian Brauner --- include/linux/user_namespace.h | 5 ++--- kernel/user.c | 2 +- kernel/user_namespace.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 6ef1c7109fc4..64cf8ebdc4ec 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -57,7 +57,6 @@ struct user_namespace { struct uid_gid_map uid_map; struct uid_gid_map gid_map; struct uid_gid_map projid_map; - atomic_t count; struct user_namespace *parent; int level; kuid_t owner; @@ -109,7 +108,7 @@ void dec_ucount(struct ucounts *ucounts, enum ucount_type type); static inline struct user_namespace *get_user_ns(struct user_namespace *ns) { if (ns) - atomic_inc(&ns->count); + refcount_inc(&ns->ns.count); return ns; } @@ -119,7 +118,7 @@ extern void __put_user_ns(struct user_namespace *ns); static inline void put_user_ns(struct user_namespace *ns) { - if (ns && atomic_dec_and_test(&ns->count)) + if (ns && refcount_dec_and_test(&ns->ns.count)) __put_user_ns(ns); } diff --git a/kernel/user.c b/kernel/user.c index b1635d94a1f2..a2478cddf536 100644 --- a/kernel/user.c +++ b/kernel/user.c @@ -55,7 +55,7 @@ struct user_namespace init_user_ns = { }, }, }, - .count = ATOMIC_INIT(3), + .ns.count = REFCOUNT_INIT(3), .owner = GLOBAL_ROOT_UID, .group = GLOBAL_ROOT_GID, .ns.inum = PROC_USER_INIT_INO, diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 87804e0371fe..7c2bbe8f3e45 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -111,7 +111,7 @@ int create_user_ns(struct cred *new) goto fail_free; ns->ns.ops = &userns_operations; - atomic_set(&ns->count, 1); + refcount_set(&ns->ns.count, 1); /* Leave the new->user_ns reference with the new user namespace. */ ns->parent = parent_ns; ns->level = parent_ns->level + 1; @@ -197,7 +197,7 @@ static void free_user_ns(struct work_struct *work) kmem_cache_free(user_ns_cachep, ns); dec_user_namespaces(ucounts); ns = parent; - } while (atomic_dec_and_test(&parent->count)); + } while (refcount_dec_and_test(&parent->ns.count)); } void __put_user_ns(struct user_namespace *ns)