Return-Path: linux-nfs-owner@vger.kernel.org Received: from cantor2.suse.de ([195.135.220.15]:38842 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753794AbaDPETQ (ORCPT ); Wed, 16 Apr 2014 00:19:16 -0400 From: NeilBrown To: linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 16 Apr 2014 14:03:36 +1000 Subject: [PATCH 12/19] NET: set PF_FSTRANS while holding rtnl_lock Cc: xfs@oss.sgi.com Cc: netdev@vger.kernel.org Message-ID: <20140416040336.10604.81658.stgit@notabene.brown> In-Reply-To: <20140416033623.10604.69237.stgit@notabene.brown> References: <20140416033623.10604.69237.stgit@notabene.brown> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sender: linux-nfs-owner@vger.kernel.org List-ID: As rtnl_mutex can be taken while holding sk_lock, and sk_lock can be taken while performing memory reclaim (at least when loop-back NFS is active), any memory allocation under rtnl_mutex must avoid __GFP_FS, which is most easily done by setting PF_MEMALLOC. CPU0 CPU1 ---- ---- lock(rtnl_mutex); lock(sk_lock-AF_INET); lock(rtnl_mutex); lock(sk_lock-AF_INET); *** DEADLOCK *** 1/ rtnl_mutex is taken while holding sk_lock: [] rtnl_lock+0x12/0x20 [] ip_mc_leave_group+0x2a/0x160 [] do_ip_setsockopt.isra.18+0x96b/0xed0 [] ip_setsockopt+0x27/0x90 [] udp_setsockopt+0x16/0x30 [] sock_common_setsockopt+0xf/0x20 [] SyS_setsockopt+0x5e/0xc0 2/ memory is allocated under rtnl_mutex: [] kobject_set_name_vargs+0x21/0x70 [] dev_set_name+0x42/0x50 [] netdev_register_kobject+0x57/0x130 [] register_netdevice+0x354/0x550 [] register_netdev+0x15/0x30 Signed-off-by: NeilBrown --- net/core/rtnetlink.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 120eecc0f5a4..6870211e93a6 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -61,15 +61,18 @@ struct rtnl_link { }; static DEFINE_MUTEX(rtnl_mutex); +static int rtnl_pflags; void rtnl_lock(void) { mutex_lock(&rtnl_mutex); + current_set_flags_nested(&rtnl_pflags, PF_FSTRANS); } EXPORT_SYMBOL(rtnl_lock); void __rtnl_unlock(void) { + current_restore_flags_nested(&rtnl_pflags, PF_FSTRANS); mutex_unlock(&rtnl_mutex); } @@ -82,7 +85,11 @@ EXPORT_SYMBOL(rtnl_unlock); int rtnl_trylock(void) { - return mutex_trylock(&rtnl_mutex); + if (mutex_trylock(&rtnl_mutex)) { + current_set_flags_nested(&rtnl_pflags, PF_FSTRANS); + return 1; + } + return 0; } EXPORT_SYMBOL(rtnl_trylock);