Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1869544ybg; Thu, 30 Jul 2020 05:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnm7MCuExWrowJR4kirPL2iKv0tsKnV8W0N8w6p5WjwtoG5xOHnpfLsT6KGiMVvEjZ1u8w X-Received: by 2002:a50:d78f:: with SMTP id w15mr2256523edi.260.1596110513330; Thu, 30 Jul 2020 05:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596110513; cv=none; d=google.com; s=arc-20160816; b=DOsYJcbeZBK6KXMPZh4+8XuVOXxUdenoGVdo/B8LmoG5wZhJnDr14HOLXQi21bQwcz dLFRoSuUREx2d0fgtbs/gCvr2p6WM/594A1fFW8zMREn8dv28mWh/rCc8Bkk76oyXvlw PJURo529xzyUbfTyL0vqtNgJ+F/oFMNVJZdMX9xnz6s5xocybredFpEUVy87ZUmMOi6T DCfEUUVIDBRuUNB4dOFAJYcmG6FbaVzV2uHWUNx6gLf2dM4bxw3GTB+8bMCLel4rgfGN 8guxo7ElA3uuSQ/wecozEVUjkiRlNUcQAXfLSo5fYRFwfF5tNE8zHX2qtJVROaBwB0vJ ZDJg== 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=hk2Vs+/LsbUD5NHQ8zlodu1Tlrbn8cq3jpH0JlZLHFw=; b=mWx9/xuccTWl8oPSEjOEWcHbZ0ZV1GgavNZA96zsWK29Ym9wOypcBx5s9mdWRKo6fn npjYzOeZERXwoCuRcIhLh/O15K+z4zQ+sMzv5gqF+ok0Z3EctHby1jYQU7S7xNfXEurG hJT7Zleyv0rDDd5AsEvxe27hFwYiI4eJt9e4uAyM8V4V4va4YdrnkilZJF3jJL33lJpO YyLyr1GLZ9Y1uK9Zitp5ReTE6FWSGfZJGKsiLddXgkaJ6th8wddv/8bqe2rwHi85/Mm6 iNmMGis1z/eH13o8cdz9/6gU179uuHEZKyjdFkliH6VgAP2q9zVdaP8V97GMii/XzU5N RkCQ== 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 b25si3068133edy.296.2020.07.30.05.01.31; Thu, 30 Jul 2020 05:01:53 -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 S1728279AbgG3MAd (ORCPT + 99 others); Thu, 30 Jul 2020 08:00:33 -0400 Received: from relay.sw.ru ([185.231.240.75]:56830 "EHLO relay3.sw.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728005AbgG3MA1 (ORCPT ); Thu, 30 Jul 2020 08:00:27 -0400 Received: from [192.168.15.64] (helo=localhost.localdomain) by relay3.sw.ru with esmtp (Exim 4.93) (envelope-from ) id 1k17EI-0002y6-PL; Thu, 30 Jul 2020 15:00:10 +0300 Subject: [PATCH 12/23] user: Free user_ns one RCU grace period after final counter put 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:00:24 +0300 Message-ID: <159611042455.535980.12021168777274312453.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 This is needed to link user_ns into ns_idr in next patch. Signed-off-by: Kirill Tkhai --- include/linux/user_namespace.h | 5 ++++- kernel/user_namespace.c | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 64cf8ebdc4ec..58fede304201 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -79,7 +79,10 @@ struct user_namespace { #ifdef CONFIG_PERSISTENT_KEYRINGS struct key *persistent_keyring_register; #endif - struct work_struct work; + union { + struct work_struct work; + struct rcu_head rcu; + }; #ifdef CONFIG_SYSCTL struct ctl_table_set set; struct ctl_table_header *sysctls; diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index 7c2bbe8f3e45..367a942bb484 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -171,6 +171,13 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred) return err; } +static void free_user_ns_rcu(struct rcu_head *head) +{ + struct user_namespace *ns = container_of(head, struct user_namespace, + rcu); + kmem_cache_free(user_ns_cachep, ns); +} + static void free_user_ns(struct work_struct *work) { struct user_namespace *parent, *ns = @@ -194,7 +201,7 @@ static void free_user_ns(struct work_struct *work) retire_userns_sysctls(ns); key_free_user_ns(ns); ns_free_inum(&ns->ns); - kmem_cache_free(user_ns_cachep, ns); + call_rcu(&ns->rcu, free_user_ns_rcu); dec_user_namespaces(ucounts); ns = parent; } while (refcount_dec_and_test(&parent->ns.count));