Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1942738pxa; Mon, 3 Aug 2020 03:20:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzAJGpBRDm6kw6rdRnE4+BF8DMaJM7Cd+eNsax26pYklUA6tS6aJF0DYG5Q8dpzG7S9y519 X-Received: by 2002:a17:906:7250:: with SMTP id n16mr16712897ejk.290.1596450032215; Mon, 03 Aug 2020 03:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596450032; cv=none; d=google.com; s=arc-20160816; b=W6Hb5mTeoB4eIFuiCUzH79c0k5zQf0ZEal7jSkf/t98wYBAVn9H8iQmaf3zqUnMV6b xC/f3QAkwnmz2v7kWb7B4kIO5g2Xgzet7nUJxssY4LXJ2bygOLWZPssM1rfFAh/HWZzs C9mxe9F8upcbm9Ty3JhrnREbMeyl1tM9MyFync6XLodmv4A7Ct2VvVMKSww6rL/A3IsH sip4uCjtCHXRD2G/zq3jYYh9oPLG75bopdr1wzCW8wEmHGfk4Fpdy6wlhowCnHvWJkUC 27cbver+a+ZIqQU0aQjQzlfwQTolD1caxZ0tStzcXVssFHbUktmTXWqyjt7H42JwLTr6 RfRg== 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=Al6uUCPUWmOQ2f5SXGs0aiw0+zaAA6Sq23N0dLHNovQ=; b=ibcRaIVkmaVsZzfxIowApkG7Bw3tj2ORWwl5d6gRJgJIic7fSB3IrQr0Rcnacv71Wq 7/SjRmdorRkFNroNEBMnOLc5TCDSiXFgR0ymCOP6oqqR7IWp03+1n7mD6IuXjiQISsL8 N/PYYen7VEwy1HMoSla5s6YYHNXXkCju7bJphL3y98IeGuOYNYhpvReQ6WcMoOQFBcvQ 81QkWYBctVeOxeo/l3y02DA23gAgMIZzMsqVsaBtX8fqNwmKbLd4cy8bGFyxYx0DLYj2 Z3+kwpNVvbi/0Yku+s+Czw2DqWCWmnYwG4dpIN/g/pjdbhHEF9GMc1WvPetwnbVYpMhA OMxw== 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 o29si10167383edz.62.2020.08.03.03.20.10; Mon, 03 Aug 2020 03:20:32 -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 S1726764AbgHCKRD (ORCPT + 99 others); Mon, 3 Aug 2020 06:17:03 -0400 Received: from relay.sw.ru ([185.231.240.75]:37986 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725951AbgHCKRD (ORCPT ); Mon, 3 Aug 2020 06:17:03 -0400 Received: from [192.168.15.50] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k2XWJ-0002Oe-Qa; Mon, 03 Aug 2020 13:16:39 +0300 Subject: [PATCH 8/8] time: 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:17:00 +0300 Message-ID: <159644982033.604812.9406853013011123238.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 time namespace to use generic counter. Signed-off-by: Kirill Tkhai Acked-by: Christian Brauner --- include/linux/time_namespace.h | 9 ++++----- kernel/time/namespace.c | 9 +++------ 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h index 5b6031385db0..a51ffc089219 100644 --- a/include/linux/time_namespace.h +++ b/include/linux/time_namespace.h @@ -4,7 +4,6 @@ #include -#include #include #include #include @@ -18,7 +17,6 @@ struct timens_offsets { }; struct time_namespace { - struct kref kref; struct user_namespace *user_ns; struct ucounts *ucounts; struct ns_common ns; @@ -37,20 +35,21 @@ extern void timens_commit(struct task_struct *tsk, struct time_namespace *ns); static inline struct time_namespace *get_time_ns(struct time_namespace *ns) { - kref_get(&ns->kref); + refcount_inc(&ns->ns.count); return ns; } struct time_namespace *copy_time_ns(unsigned long flags, struct user_namespace *user_ns, struct time_namespace *old_ns); -void free_time_ns(struct kref *kref); +void free_time_ns(struct time_namespace *ns); int timens_on_fork(struct nsproxy *nsproxy, struct task_struct *tsk); struct vdso_data *arch_get_vdso_data(void *vvar_page); static inline void put_time_ns(struct time_namespace *ns) { - kref_put(&ns->kref, free_time_ns); + if (refcount_dec_and_test(&ns->ns.count)) + free_time_ns(ns); } void proc_timens_show_offsets(struct task_struct *p, struct seq_file *m); diff --git a/kernel/time/namespace.c b/kernel/time/namespace.c index afc65e6be33e..c4c829eb3511 100644 --- a/kernel/time/namespace.c +++ b/kernel/time/namespace.c @@ -92,7 +92,7 @@ static struct time_namespace *clone_time_ns(struct user_namespace *user_ns, if (!ns) goto fail_dec; - kref_init(&ns->kref); + refcount_set(&ns->ns.count, 1); ns->vvar_page = alloc_page(GFP_KERNEL | __GFP_ZERO); if (!ns->vvar_page) @@ -226,11 +226,8 @@ static void timens_set_vvar_page(struct task_struct *task, mutex_unlock(&offset_lock); } -void free_time_ns(struct kref *kref) +void free_time_ns(struct time_namespace *ns) { - struct time_namespace *ns; - - ns = container_of(kref, struct time_namespace, kref); dec_time_namespaces(ns->ucounts); put_user_ns(ns->user_ns); ns_free_inum(&ns->ns); @@ -464,7 +461,7 @@ const struct proc_ns_operations timens_for_children_operations = { }; struct time_namespace init_time_ns = { - .kref = KREF_INIT(3), + .ns.count = REFCOUNT_INIT(3), .user_ns = &init_user_ns, .ns.inum = PROC_TIME_INIT_INO, .ns.ops = &timens_operations,