From patchwork Mon Nov 20 18:32:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 839711 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="d5ZJwIEL"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ygd0Z18F0z9rxj for ; Tue, 21 Nov 2017 05:43:58 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752275AbdKTSct (ORCPT ); Mon, 20 Nov 2017 13:32:49 -0500 Received: from mail-he1eur01on0121.outbound.protection.outlook.com ([104.47.0.121]:45291 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752018AbdKTScp (ORCPT ); Mon, 20 Nov 2017 13:32:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=G0TEkkyO2zOXveY/4sHRNZJz2EODInrQEWRgwGcj/I0=; b=d5ZJwIELVRwkTorBWFDdBq4gK1PaSw+TPlfV0gCqnOXz+lc7LceQy6EBt3raAHzTd9JI6mG5ZJiKGrR3S7wJ8fwNqRr59NCTkmt8WvotZtxYuMgWKxiwEVZXXK6FvB6JUM8XWF0/nZG2jf1DMSDxXwxbdYgOe88PHM7FmKVLWBI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by AM5PR0801MB1329.eurprd08.prod.outlook.com (2603:10a6:203:1f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.218.12; Mon, 20 Nov 2017 18:32:37 +0000 Subject: [PATCH v2 03/31] net: Introduce net_sem for protection of pernet_list From: Kirill Tkhai To: davem@davemloft.net, vyasevic@redhat.com, kstewart@linuxfoundation.org, pombredanne@nexb.com, vyasevich@gmail.com, mark.rutland@arm.com, gregkh@linuxfoundation.org, adobriyan@gmail.com, fw@strlen.de, nicolas.dichtel@6wind.com, xiyou.wangcong@gmail.com, roman.kapl@sysgo.com, paul@paul-moore.com, dsahern@gmail.com, daniel@iogearbox.net, lucien.xin@gmail.com, mschiffer@universe-factory.net, rshearma@brocade.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, ktkhai@virtuozzo.com, ebiederm@xmission.com, avagin@virtuozzo.com, gorcunov@virtuozzo.com, eric.dumazet@gmail.com, stephen@networkplumber.org, ktkhai@virtuozzo.com Date: Mon, 20 Nov 2017 21:32:34 +0300 Message-ID: <151120275448.3159.9199776106492105413.stgit@localhost.localdomain> In-Reply-To: <151120175301.3159.9577108443167812854.stgit@localhost.localdomain> References: <151120175301.3159.9577108443167812854.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0902CA0003.eurprd09.prod.outlook.com (2603:10a6:3:e5::13) To AM5PR0801MB1329.eurprd08.prod.outlook.com (2603:10a6:203:1f::7) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8acb7b0-d458-442a-5f47-08d530451454 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603199); SRVR:AM5PR0801MB1329; X-Microsoft-Exchange-Diagnostics: 1;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VBAbYHygZDIIS5NZG8pY6MVYjq29fIboeRwbUpcKN84M5KPAYOWcTxvWVYqlLTFAZn7SqNM8iol7hm/BrTy7m3QNBHtdj7s06YmrP898TYFVbQTykDcofXqLLP1pmA0QcypXiJV/fUjpCPDKlSx3iQ4k/0MqzjbNOR16SuTXgjMbueth8GJULHqh5mTYwOB6wd9+NF11UBO9stdLSm0hHnizR1Fpt9LxzxcAEny/5COj6qR4yuvC/FXWTJVdnnDpDF1Sr4Worn9j+i8g=; 4:PgIonhZuo9NBDgIaXBFJzZOWAxietOTNPsMzI+IMVuZ/K98/W5F3sosejsOVJnkgkn2Q3otXxizGbb4FeIUo4dAtlzsATaDu0mphTC2NEt7tEKIUFgj+HYO0c/2xU9PL7DX1eojHWBGMvn6Ff7RirCgopXw+A8Jsdw9RskSIBYZ22ALtZiuMZvFDqcktLmgiCHcoO2h6Ebsomswf/mvrBVkUOwYXWDnXIcI4EJkaFzErVe3czj/Z60RcHtOU28TCr2zxP7VxRA8gNgiprnnFTg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(100000703101)(100105400095)(10201501046)(3002001)(3231022)(93006095)(93001095)(6041248)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123558100)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM5PR0801MB1329; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5PR0801MB1329; X-Forefront-PRVS: 04976078F0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(6009001)(346002)(376002)(189002)(199003)(5660300001)(66066001)(105586002)(50466002)(58126008)(39060400002)(97736004)(6116002)(101416001)(106356001)(54356999)(76176999)(16526018)(68736007)(50986999)(3846002)(8936002)(8676002)(47776003)(81166006)(81156014)(2950100002)(33646002)(230700001)(2906002)(6666003)(83506002)(103116003)(478600001)(7416002)(189998001)(55236003)(7736002)(305945005)(23676003)(55016002)(316002)(53936002)(6506006)(9686003)(25786009)(86362001)(61506002)(921003)(1121003); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1329; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?q?1=3BAM5PR0801MB1329=3B23=3AjP?= =?utf-8?q?IVmn6iE9a0xFUhQuryUhSRyYMR388uoWtSvvL9Fdd828PgT7AvIJ02Vb?= =?utf-8?q?5g9m/HVj1cpAwi4FPMHuWdpL5A5SFtzdLs99Vlfrq92vtJqlAQVwwlCr?= =?utf-8?q?a/p3ia/lACU97ilPwGCl88WXmsjEzAu4QRhf5e4DhmnKU0ss3/b1QAWu?= =?utf-8?q?FRqmDv9WMnipPMNNKmpxYnj8mQHSlWIubU69gD6cIDHNMJRg65Lrdwuq?= =?utf-8?q?gQxoQyglLh0bfiTMUExpWxr+Tt2rNqhlFcQuZ9N8/mhg3gziTwR03du3?= =?utf-8?q?sT9NxML+I2kxAvoTWi5UuEy2afrwkAusYzyeI/bOXVSj2k9I8o21DMo8?= =?utf-8?q?LeP6xtc/mhzDQ6sL/Hcu88CVnp4S+zZDn1S15TsKkuhCpcytC9wLFLzD?= =?utf-8?q?ibQA+KdESakBpNel5WIe2G8S3ueckxUnVv9LFEMHcbqWEvX5zuaRCw/c?= =?utf-8?q?JG/qTS9x3MrdsFA3rngp/uNN2doaNplj79XKD4HBw/88JQHl7jxbba/Q?= =?utf-8?q?gH81r/7+7mDAtPoe3bgqvEQ0h7fFKEUzL9TLCICVxVaxHjHVjM77NO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etp27iK5NY8Pdp24oT62QEyCOJA3N2ut//sqTyw5gcwrQ0J0lPVS3sT23lyE8yhm85u6MyzNN/1CZK9+QMPD48jiOzO5rvvqw=; 5:BOf/Bjat5LtYqMPvnyOB5WLa3HxmcDktqJyWzd6WxC2TjlLN2H+oqwWNrD6ICVwgDpqQOC+dXgRQksWQpMAhyvmEMYxM9zQrQiYTZZjFx8uR83m542T+5xxzpRkOUYKkhiTIcAhljMMWOGHcbqqYp9VzXb+xDB60qq5muAkFAyc=; 24:lEeKp2gakXklrKEiEiG2MsGNs9Rv7IHEmGiaB++Iv7LV0GZMI6Zk5cm4dU9SzIiekQxfWLmEwOWKymDl4FFnu+rTh2ewFBEYDVTpeM/kFbg=; 7:7x60Tw/a87GrFMtD1UoOfbtCZ9ED8w7i5nVWoGL6hCp0jO7DphircpTuiHmKxZmqPU2JIkREcs7nDUahaw/CXf8+5BIsAnRwYx4k/vp8Yy4iT6HV+rTMlxZoWD6/UzLuLzNLHB6ZA70BCgPWFsQybyxM0XQjKBv1bOA5njUr23QXeYJ5Ayqi7FfWJsV6pIn3SxJEisPHLrogOGWvSP+NupwFvlH/hFy/EBHytHt4oTDfgqe3XDhpj+pmY39ie/FU SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1329; 20:MRSenmlaEfCH3qJal06qvbfiuxfNj9Re+GK0SfmVOGtGEKbR3e+iL3t4DxzIEgagzNpU+ybN/+fqr6jXJ7r2Sdhc9swMAFHwnzZrw0sxa0/34yPGgt8wtPC+llQapAMIuVhet+qmqEARfyjrQMN/RFSsa8wknLXRt1OHbH+m84k= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2017 18:32:37.6461 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8acb7b0-d458-442a-5f47-08d530451454 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1329 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Curently mutex is used to protect pernet operations list. It makes cleanup_net() to execute ->exit methods of the same operations set, which was used on the time of ->init, even after net namespace is unlinked from net_namespace_list. But the problem is it's need to synchronize_rcu() after net is removed from net_namespace_list(): Destroy net_ns: cleanup_net() mutex_lock(&net_mutex) list_del_rcu(&net->list) synchronize_rcu() <--- Sleep there for ages list_for_each_entry_reverse(ops, &pernet_list, list) ops_exit_list(ops, &net_exit_list) list_for_each_entry_reverse(ops, &pernet_list, list) ops_free_list(ops, &net_exit_list) mutex_unlock(&net_mutex) This primitive is not fast, especially on the systems with many processors and/or when preemptible RCU is enabled in config. So, all the time, while cleanup_net() is waiting for RCU grace period, creation of new net namespaces is not possible, the tasks, who makes it, are sleeping on the same mutex: Create net_ns: copy_net_ns() mutex_lock_killable(&net_mutex) <--- Sleep there for ages I observed 20-30 seconds hangs of "unshare -n" on ordinary 8-cpu laptop with preemptible RCU enabled. The solution is to convert net_mutex to the rw_semaphore and add small locks to really small number of pernet_operations, what really need them. Then, pernet_operations::init/::exit methods, modifying the net-related data, will require down_read() locking only, while down_write() will be used for changing pernet_list. This gives signify performance increase, after all patch set is applied, like you may see here: %for i in {1..10000}; do unshare -n bash -c exit; done *before* real 1m40,377s user 0m9,672s sys 0m19,928s *after* real 0m17,007s user 0m5,311s sys 0m11,779 (5.8 times faster) This patch starts replacing net_mutex to net_sem. It adds rw_semaphore, describes the variables it protects, and makes to use where appropriate. net_mutex is still present, and next patches will kick it out step-by-step. Signed-off-by: Kirill Tkhai --- include/linux/rtnetlink.h | 1 + net/core/net_namespace.c | 39 ++++++++++++++++++++++++++------------- net/core/rtnetlink.c | 4 ++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 2032ce2eb20b..f640fc87fe1d 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h @@ -35,6 +35,7 @@ extern int rtnl_is_locked(void); extern wait_queue_head_t netdev_unregistering_wq; extern struct mutex net_mutex; +extern struct rw_semaphore net_sem; #ifdef CONFIG_PROVE_LOCKING extern bool lockdep_rtnl_is_held(void); diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 2e512965bf42..859dce31e37e 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -41,6 +41,11 @@ struct net init_net = { EXPORT_SYMBOL(init_net); static bool init_net_initialized; +/* + * net_sem: protects: pernet_list, net_generic_ids, + * init_net_initialized and first_device pointer. + */ +DECLARE_RWSEM(net_sem); #define MIN_PERNET_OPS_ID \ ((sizeof(struct net_generic) + sizeof(void *) - 1) / sizeof(void *)) @@ -279,7 +284,7 @@ struct net *get_net_ns_by_id(struct net *net, int id) */ static __net_init int setup_net(struct net *net, struct user_namespace *user_ns) { - /* Must be called with net_mutex held */ + /* Must be called with net_sem held */ const struct pernet_operations *ops, *saved_ops; int error = 0; LIST_HEAD(net_exit_list); @@ -411,12 +416,16 @@ struct net *copy_net_ns(unsigned long flags, net->ucounts = ucounts; get_user_ns(user_ns); - rv = mutex_lock_killable(&net_mutex); + rv = down_read_killable(&net_sem); if (rv < 0) goto put_userns; - + rv = mutex_lock_killable(&net_mutex); + if (rv < 0) + goto up_read; rv = setup_net(net, user_ns); mutex_unlock(&net_mutex); +up_read: + up_read(&net_sem); if (rv < 0) { put_userns: put_user_ns(user_ns); @@ -443,6 +452,7 @@ static void cleanup_net(struct work_struct *work) list_replace_init(&cleanup_list, &net_kill_list); spin_unlock_irq(&cleanup_list_lock); + down_read(&net_sem); mutex_lock(&net_mutex); /* Don't let anyone else find us. */ @@ -484,6 +494,7 @@ static void cleanup_net(struct work_struct *work) ops_free_list(ops, &net_exit_list); mutex_unlock(&net_mutex); + up_read(&net_sem); /* Ensure there are no outstanding rcu callbacks using this * network namespace. @@ -510,8 +521,10 @@ static void cleanup_net(struct work_struct *work) */ void net_ns_barrier(void) { + down_write(&net_sem); mutex_lock(&net_mutex); mutex_unlock(&net_mutex); + up_write(&net_sem); } EXPORT_SYMBOL(net_ns_barrier); @@ -838,12 +851,12 @@ static int __init net_ns_init(void) rcu_assign_pointer(init_net.gen, ng); - mutex_lock(&net_mutex); + down_write(&net_sem); if (setup_net(&init_net, &init_user_ns)) panic("Could not setup the initial network namespace"); init_net_initialized = true; - mutex_unlock(&net_mutex); + up_write(&net_sem); register_pernet_subsys(&net_ns_ops); @@ -983,9 +996,9 @@ static void unregister_pernet_operations(struct pernet_operations *ops) int register_pernet_subsys(struct pernet_operations *ops) { int error; - mutex_lock(&net_mutex); + down_write(&net_sem); error = register_pernet_operations(first_device, ops); - mutex_unlock(&net_mutex); + up_write(&net_sem); return error; } EXPORT_SYMBOL_GPL(register_pernet_subsys); @@ -1001,9 +1014,9 @@ EXPORT_SYMBOL_GPL(register_pernet_subsys); */ void unregister_pernet_subsys(struct pernet_operations *ops) { - mutex_lock(&net_mutex); + down_write(&net_sem); unregister_pernet_operations(ops); - mutex_unlock(&net_mutex); + up_write(&net_sem); } EXPORT_SYMBOL_GPL(unregister_pernet_subsys); @@ -1029,11 +1042,11 @@ EXPORT_SYMBOL_GPL(unregister_pernet_subsys); int register_pernet_device(struct pernet_operations *ops) { int error; - mutex_lock(&net_mutex); + down_write(&net_sem); error = register_pernet_operations(&pernet_list, ops); if (!error && (first_device == &pernet_list)) first_device = &ops->list; - mutex_unlock(&net_mutex); + up_write(&net_sem); return error; } EXPORT_SYMBOL_GPL(register_pernet_device); @@ -1049,11 +1062,11 @@ EXPORT_SYMBOL_GPL(register_pernet_device); */ void unregister_pernet_device(struct pernet_operations *ops) { - mutex_lock(&net_mutex); + down_write(&net_sem); if (&ops->list == first_device) first_device = first_device->next; unregister_pernet_operations(ops); - mutex_unlock(&net_mutex); + up_write(&net_sem); } EXPORT_SYMBOL_GPL(unregister_pernet_device); diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index dabba2a91fc8..cb06d43c4230 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -390,11 +390,11 @@ static void rtnl_lock_unregistering_all(void) void rtnl_link_unregister(struct rtnl_link_ops *ops) { /* Close the race with cleanup_net() */ - mutex_lock(&net_mutex); + down_write(&net_sem); rtnl_lock_unregistering_all(); __rtnl_link_unregister(ops); rtnl_unlock(); - mutex_unlock(&net_mutex); + up_write(&net_sem); } EXPORT_SYMBOL_GPL(rtnl_link_unregister);