Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755035AbcJUCqE (ORCPT ); Thu, 20 Oct 2016 22:46:04 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:33328 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754954AbcJUCp4 (ORCPT ); Thu, 20 Oct 2016 22:45:56 -0400 From: Andrei Vagin To: "David S. Miller" Cc: "Eric W . Biederman" , containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Andrey Vagin Subject: [PATCH net-next] net: allow to kill a task which waits net_mutex in copy_new_ns Date: Thu, 20 Oct 2016 19:45:43 -0700 Message-Id: <1477017943-18786-1-git-send-email-avagin@openvz.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1060 Lines: 38 From: Andrey Vagin net_mutex can be locked for a long time. It may be because many namespaces are being destroyed or many processes decide to create a network namespace. Both these operations are heavy, so it is better to have an ability to kill a process which is waiting net_mutex. Cc: "David S. Miller" Cc: Eric W. Biederman Signed-off-by: Andrei Vagin --- net/core/net_namespace.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 989434f..b9243b1 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -379,7 +379,14 @@ struct net *copy_net_ns(unsigned long flags, get_user_ns(user_ns); - mutex_lock(&net_mutex); + rv = mutex_lock_killable(&net_mutex); + if (rv < 0) { + net_free(net); + dec_net_namespaces(ucounts); + put_user_ns(user_ns); + return ERR_PTR(rv); + } + net->ucounts = ucounts; rv = setup_net(net, user_ns); if (rv == 0) { -- 2.7.4