Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1992177ybg; Thu, 30 Jul 2020 07:49:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPE4lDrp1sahO+6J96QoxuNjexKrxJvLTuAwEaShySY6DDt0kg/Dmi1F80VOfaVwKMvJrc X-Received: by 2002:a17:906:444e:: with SMTP id i14mr2855381ejp.418.1596120571542; Thu, 30 Jul 2020 07:49:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596120571; cv=none; d=google.com; s=arc-20160816; b=jgP6bhZoAe8yZLp9sA5ZmEibdg27l1JfY7D9BbE4oxlfjlc88r01FWUfqCtx5KTDWM Oq7Wo8lXVkd6s642H7xv1gGtsGXmRfU9W6fp9LckdMzRCTk0szUlcWPiO2dABsxGYAvX +WX8YnOFEMGqVLLzlwi0TAbh7et7V4bmekYp2wPZl9S1qgfavWioB1KyBVQFzNpA+u/S 6nmGqAKTGNE3xJptXNWbUG70yYGIpiGQuMUeGO/5QzPFkYzS1oqoFLn03sv7k1bzkGXv 2qZES504zWM2LDKXz90LJkrYWYBJruIsfc2Mk+O9+ZY1F1tvNerRqQuArRw1c1B6eBDS bY/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=vy7w1GOuMFStHK63J/dDmN/xJa8SEQZR/16CH5MDMzc=; b=0wnCOwP84tB4lScKSn9MaB9Ja99A0SMwcHSukK2dcNGzkX4jzO5icQy3EJUD1p/wXb 1+94cly5xFlPxAX6XgJ2soWX9iKdTLO8J+ZDBzrE7Rrr4HFaoAesQVLBfJMq5D6ZqNu1 QZtXAFeCLrW3c8gpEc+xWTO7vive222jkZ0y/NRKWGZsTBlgFeY6j7Djl2VFDFQmZJGc Ad8ekmSTyAk/7wQiH4HA8ui9DJcRkRUsqn97VQXZ0jh86jDozfMKkFd4ERnj2CUFnLH2 tkxCtAaSJftwF6lBTzA866bCBcnQ22WRmCx7xtQQ3lKMewwkTbSEftXTLhKVU3z3hGgR V7QQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i21si3183488eje.143.2020.07.30.07.49.09; Thu, 30 Jul 2020 07:49:31 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728462AbgG3OrJ (ORCPT + 99 others); Thu, 30 Jul 2020 10:47:09 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:53496 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbgG3OrI (ORCPT ); Thu, 30 Jul 2020 10:47:08 -0400 Received: from ip5f5af08c.dynamic.kabel-deutschland.de ([95.90.240.140] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1k19pS-0001p0-Ro; Thu, 30 Jul 2020 14:46:42 +0000 Date: Thu, 30 Jul 2020 16:46:41 +0200 From: Christian Brauner To: Kirill Tkhai Cc: viro@zeniv.linux.org.uk, adobriyan@gmail.com, davem@davemloft.net, ebiederm@xmission.com, akpm@linux-foundation.org, areber@redhat.com, serge@hallyn.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH 05/23] user: Use generic ns_common::count Message-ID: <20200730144641.rep2ht5lmnryfhzj@wittgenstein> References: <159611007271.535980.15362304262237658692.stgit@localhost.localdomain> <159611038719.535980.13960315152927389105.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <159611038719.535980.13960315152927389105.stgit@localhost.localdomain> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 30, 2020 at 02:59:47PM +0300, Kirill Tkhai wrote: > Convert user namespace to use generic counter. > > Signed-off-by: Kirill Tkhai > --- Looks good! 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), Note-to-self: I really wish we'd had a comment in cases where the refcount isn't set to 1 but to something like 3. Otherwise one always needs to dig up the reasons why. :) > .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) > >